Module: Pluckr::Aliases
- Defined in:
- lib/pluckr/aliases.rb
Overview
Single source of truth for the flat column aliases used in generated SQL.
The SQL stays flat; nesting lives in the alias path:
users.id AS "id"
subscriptions.name AS "subscription.name"
subscriptions.id AS "__pluckr.subscription.present"
The result builder reads the same helpers back, so the encoding is never duplicated between the compiler and the hydrator.
Constant Summary collapse
- SEPARATOR =
"."- PRESENCE_PREFIX =
"__pluckr"- PRESENCE_SUFFIX =
"present"- TABLE_PREFIX =
"pluckr"
Class Method Summary collapse
-
.output(path, name) ⇒ Object
Output alias for a value node, e.g.
-
.presence(path) ⇒ Object
Hidden marker telling the hydrator whether a nested
onerow exists at all. -
.table(path) ⇒ Object
Table alias for a joined singular association.
Class Method Details
.output(path, name) ⇒ Object
Output alias for a value node, e.g. ["subscription"], :name => "subscription.name"
23 24 25 |
# File 'lib/pluckr/aliases.rb', line 23 def output(path, name) (path + [name]).join(SEPARATOR) end |
.presence(path) ⇒ Object
Hidden marker telling the hydrator whether a nested one row exists at all.
28 29 30 |
# File 'lib/pluckr/aliases.rb', line 28 def presence(path) ([PRESENCE_PREFIX] + path + [PRESENCE_SUFFIX]).join(SEPARATOR) end |
.table(path) ⇒ Object
Table alias for a joined singular association.
33 34 35 |
# File 'lib/pluckr/aliases.rb', line 33 def table(path) ([TABLE_PREFIX] + path).join("_") end |