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.
-
#group_by ⇒ Object
readonly
Returns the value of attribute group_by.
-
#having ⇒ Object
readonly
Returns the value of attribute having.
-
#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
These are overwritten, not appended to.
-
#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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/seaquel/statement.rb', line 34 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 = [] @having = AST::JoinOp.new(:and, []) @group_by = list() 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.
23 24 25 |
# File 'lib/seaquel/statement.rb', line 23 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 |
#group_by ⇒ Object (readonly)
Returns the value of attribute group_by.
32 33 34 |
# File 'lib/seaquel/statement.rb', line 32 def group_by @group_by end |
#having ⇒ Object (readonly)
Returns the value of attribute having.
27 28 29 |
# File 'lib/seaquel/statement.rb', line 27 def having @having end |
#joins ⇒ Object (readonly)
Returns the value of attribute joins.
24 25 26 |
# File 'lib/seaquel/statement.rb', line 24 def joins @joins end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
25 26 27 |
# File 'lib/seaquel/statement.rb', line 25 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
26 27 28 |
# File 'lib/seaquel/statement.rb', line 26 def offset @offset end |
#order_by ⇒ Object (readonly)
Returns the value of attribute order_by.
31 32 33 |
# File 'lib/seaquel/statement.rb', line 31 def order_by @order_by end |
#project ⇒ Object (readonly)
These are overwritten, not appended to.
30 31 32 |
# File 'lib/seaquel/statement.rb', line 30 def project @project end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
20 21 22 |
# File 'lib/seaquel/statement.rb', line 20 def set @set end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
21 22 23 |
# File 'lib/seaquel/statement.rb', line 21 def target @target end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
22 23 24 |
# File 'lib/seaquel/statement.rb', line 22 def values @values end |
#where ⇒ Object (readonly)
Returns the value of attribute where.
19 20 21 |
# File 'lib/seaquel/statement.rb', line 19 def where @where end |
Instance Method Details
#convert(exp) ⇒ Object
Turns an expression into SQL
95 96 97 |
# File 'lib/seaquel/statement.rb', line 95 def convert exp expression_convertor.sql(exp).toplevel end |
#join(tables) ⇒ Join
Produces a join clause and adds it to the joins list.
73 74 75 76 77 78 |
# File 'lib/seaquel/statement.rb', line 73 def join tables join = Join.new(tables) joins << join join end |
#set_limit(n) ⇒ Object
49 50 51 |
# File 'lib/seaquel/statement.rb', line 49 def set_limit n @limit = n end |
#set_offset(n) ⇒ Object
52 53 54 |
# File 'lib/seaquel/statement.rb', line 52 def set_offset n @offset = n end |
#set_target(table) ⇒ Object
64 65 66 |
# File 'lib/seaquel/statement.rb', line 64 def set_target table @target = table end |
#set_type(type) ⇒ Object
Allows to determine the type of statement generated.
60 61 62 |
# File 'lib/seaquel/statement.rb', line 60 def set_type type @type = type end |
#to_s(variant = :compact) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/seaquel/statement.rb', line 80 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 |