Class: Seaquel::Statement
- Inherits:
-
Object
- Object
- Seaquel::Statement
- Defined in:
- lib/seaquel/statement.rb,
lib/seaquel/statement/join.rb
Overview
Root node for an sql statement.
Defined Under Namespace
Classes: Join
Instance Attribute Summary collapse
-
#expression_convertor ⇒ Object
readonly
Returns the value of attribute expression_convertor.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#joins ⇒ Object
readonly
Returns the value of attribute joins.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#order_by ⇒ Object
readonly
Returns the value of attribute order_by.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
-
#where ⇒ Object
readonly
Returns the value of attribute where.
Instance Method Summary collapse
-
#convert(exp) ⇒ Object
Turns an expression into SQL.
-
#initialize(expression_convertor) ⇒ Statement
constructor
A new instance of Statement.
-
#join(tables) ⇒ Join
Produces a join clause and adds it to the joins list.
- #set_limit(n) ⇒ Object
- #set_offset(n) ⇒ Object
- #set_target(table) ⇒ Object
-
#set_type(type) ⇒ Object
Allows to determine the type of statement generated.
- #to_s(variant = :compact) ⇒ Object
Constructor Details
#initialize(expression_convertor) ⇒ Statement
Returns a new instance of Statement.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/seaquel/statement.rb', line 30 def initialize expression_convertor @expression_convertor = expression_convertor @from = list() @project = list() @order_by = list() @where = AST::JoinOp.new(:and, []) @set = list() @values = list() @fields = column_list() @joins = [] end |
Instance Attribute Details
#expression_convertor ⇒ Object (readonly)
Returns the value of attribute expression_convertor.
16 17 18 |
# File 'lib/seaquel/statement.rb', line 16 def expression_convertor @expression_convertor end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
24 25 26 |
# File 'lib/seaquel/statement.rb', line 24 def fields @fields end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
18 19 20 |
# File 'lib/seaquel/statement.rb', line 18 def from @from end |
#joins ⇒ Object (readonly)
Returns the value of attribute joins.
25 26 27 |
# File 'lib/seaquel/statement.rb', line 25 def joins @joins end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
26 27 28 |
# File 'lib/seaquel/statement.rb', line 26 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
27 28 29 |
# File 'lib/seaquel/statement.rb', line 27 def offset @offset end |
#order_by ⇒ Object (readonly)
Returns the value of attribute order_by.
28 29 30 |
# File 'lib/seaquel/statement.rb', line 28 def order_by @order_by end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
19 20 21 |
# File 'lib/seaquel/statement.rb', line 19 def project @project end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
21 22 23 |
# File 'lib/seaquel/statement.rb', line 21 def set @set end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
22 23 24 |
# File 'lib/seaquel/statement.rb', line 22 def target @target end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
23 24 25 |
# File 'lib/seaquel/statement.rb', line 23 def values @values end |
#where ⇒ Object (readonly)
Returns the value of attribute where.
20 21 22 |
# File 'lib/seaquel/statement.rb', line 20 def where @where end |
Instance Method Details
#convert(exp) ⇒ Object
Turns an expression into SQL
89 90 91 |
# File 'lib/seaquel/statement.rb', line 89 def convert exp expression_convertor.sql(exp).toplevel end |
#join(tables) ⇒ Join
Produces a join clause and adds it to the joins list.
67 68 69 70 71 72 |
# File 'lib/seaquel/statement.rb', line 67 def join tables join = Join.new(tables) joins << join join end |
#set_limit(n) ⇒ Object
43 44 45 |
# File 'lib/seaquel/statement.rb', line 43 def set_limit n @limit = n end |
#set_offset(n) ⇒ Object
46 47 48 |
# File 'lib/seaquel/statement.rb', line 46 def set_offset n @offset = n end |
#set_target(table) ⇒ Object
58 59 60 |
# File 'lib/seaquel/statement.rb', line 58 def set_target table @target = table end |
#set_type(type) ⇒ Object
Allows to determine the type of statement generated.
54 55 56 |
# File 'lib/seaquel/statement.rb', line 54 def set_type type @type = type end |
#to_s(variant = :compact) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/seaquel/statement.rb', line 74 def to_s variant=:compact case @type when :update generate_update(variant) when :insert generate_insert(variant) when :delete generate_delete(variant) else generate_select(variant) end end |