Class: Seaquel::AST::Node
- Inherits:
-
Object
- Object
- Seaquel::AST::Node
- Defined in:
- lib/seaquel/ast/node.rb
Overview
A general purpose node containing a node type and a list of arguments. The node stores a link to its parent or nil if no such parent exists. This class can be visited.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#fields(*list) ⇒ Object
INSERT INTO …
- #from(*tables) ⇒ Object
- #group_by(*fields) ⇒ Object
- #having(*exps) ⇒ Object
-
#initialize(*args) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #into(table) ⇒ Object
- #join(*tables) ⇒ Object
- #limit(n) ⇒ Object
- #node(*args) ⇒ Object
- #offset(n) ⇒ Object
- #on(*exps) ⇒ Object
-
#order_by(*list) ⇒ Node
Replaces previous ORDER BY specification with this one.
-
#project(*fields) ⇒ Node
Replaces previous projection list with this one.
- #set(*assign_list) ⇒ Object
- #to_sql ⇒ Object
-
#values(*list) ⇒ AST::Node
Adds a values list to an INSERT statement.
- #visit(visitor) ⇒ Object
- #where(*exps) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Node
Returns a new instance of Node.
11 12 13 14 15 16 17 |
# File 'lib/seaquel/ast/node.rb', line 11 def initialize *args if args.first.kind_of?(Symbol) @type, *@args = args else @parent, @type, *@args = args end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
9 10 11 |
# File 'lib/seaquel/ast/node.rb', line 9 def args @args end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
8 9 10 |
# File 'lib/seaquel/ast/node.rb', line 8 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/seaquel/ast/node.rb', line 7 def type @type end |
Instance Method Details
#fields(*list) ⇒ Object
INSERT INTO … (FIELDS) VALUES (…)
71 72 73 |
# File 'lib/seaquel/ast/node.rb', line 71 def fields *list node(:fields, list) end |
#from(*tables) ⇒ Object
28 29 30 |
# File 'lib/seaquel/ast/node.rb', line 28 def from *tables node(:from, *tables) end |
#group_by(*fields) ⇒ Object
57 58 59 |
# File 'lib/seaquel/ast/node.rb', line 57 def group_by *fields node(:group_by, fields) end |
#having(*exps) ⇒ Object
54 55 56 |
# File 'lib/seaquel/ast/node.rb', line 54 def having *exps node(:having, exps) end |
#inspect ⇒ Object
112 113 114 |
# File 'lib/seaquel/ast/node.rb', line 112 def inspect [type, args, parent].inspect end |
#into(table) ⇒ Object
91 92 93 |
# File 'lib/seaquel/ast/node.rb', line 91 def into table node(:into, table) end |
#join(*tables) ⇒ Object
40 41 42 |
# File 'lib/seaquel/ast/node.rb', line 40 def join *tables node(:join, tables) end |
#limit(n) ⇒ Object
47 48 49 |
# File 'lib/seaquel/ast/node.rb', line 47 def limit n node(:limit, n) end |
#node(*args) ⇒ Object
95 96 97 |
# File 'lib/seaquel/ast/node.rb', line 95 def node *args self.class.new(self, *args) end |
#offset(n) ⇒ Object
50 51 52 |
# File 'lib/seaquel/ast/node.rb', line 50 def offset n node(:offset, n) end |
#on(*exps) ⇒ Object
43 44 45 |
# File 'lib/seaquel/ast/node.rb', line 43 def on *exps node(:on, exps) end |
#order_by(*list) ⇒ Node
Replaces previous ORDER BY specification with this one.
66 67 68 |
# File 'lib/seaquel/ast/node.rb', line 66 def order_by *list node(:order_by, list) end |
#project(*fields) ⇒ Node
Replaces previous projection list with this one.
24 25 26 |
# File 'lib/seaquel/ast/node.rb', line 24 def project *fields node(:project, fields) end |
#set(*assign_list) ⇒ Object
36 37 38 |
# File 'lib/seaquel/ast/node.rb', line 36 def set *assign_list node(:set, assign_list) end |
#to_sql ⇒ Object
108 109 110 |
# File 'lib/seaquel/ast/node.rb', line 108 def to_sql ::Seaquel::Generator.new(self).compact_sql end |
#values(*list) ⇒ AST::Node
Adds a values list to an INSERT statement. You have to pass all the columns at once; repeating this method call will create an INSERT statement that inserts multiple rows at once (a Postgres extension).
Example:
include Seaquel
insert.into(table('foo')).values(1, 2)
# => INSERT INTO "foo" VALUES (1, 2)
87 88 89 |
# File 'lib/seaquel/ast/node.rb', line 87 def values *list node(:values, list) end |
#visit(visitor) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/seaquel/ast/node.rb', line 99 def visit visitor method_name = "visit_#{type}" if visitor.respond_to?(:visit_node) visitor.visit_node(self) else visitor.send(method_name, parent, *args) end end |