Class: AlgebraDB::Build::Join

Inherits:
Struct
  • Object
show all
Defined in:
lib/algebra_db/build/join.rb

Overview

Syntax for a join.

Constant Summary collapse

JOIN_EXPRS =
{
  inner: 'INNER JOIN',
  left: 'LEFT OUTER JOIN',
  right: 'RIGHT OUTER JOIN',
  inner_lateral: 'INNER JOIN LATERAL',
  left_lateral: 'LEFT JOIN LATERAL',
  right_lateral: 'RIGHT JOIN LATERAL'
}.freeze
TYPES =
JOIN_EXPRS.keys.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, table, condition) ⇒ Join

Returns a new instance of Join.

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/algebra_db/build/join.rb', line 17

def initialize(type, table, condition)
  super(type, table, condition)

  raise ArgumentError, "unrecognized join type #{type}" unless TYPES.include?(type)
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition

Returns:

  • (Object)

    the current value of condition



5
6
7
# File 'lib/algebra_db/build/join.rb', line 5

def condition
  @condition
end

#tableObject

Returns the value of attribute table

Returns:

  • (Object)

    the current value of table



5
6
7
# File 'lib/algebra_db/build/join.rb', line 5

def table
  @table
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



5
6
7
# File 'lib/algebra_db/build/join.rb', line 5

def type
  @type
end

Instance Method Details

#join_exprObject



30
31
32
# File 'lib/algebra_db/build/join.rb', line 30

def join_expr
  JOIN_EXPRS[type]
end

#render_syntax(builder) ⇒ Object



23
24
25
26
27
28
# File 'lib/algebra_db/build/join.rb', line 23

def render_syntax(builder)
  builder.text(join_expr)
  table.render_syntax(builder)
  builder.text('ON')
  condition.render_syntax(builder)
end