class Seaquel::AST::Node
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.
Attributes
args[R]
parent[R]
type[R]
Public Class Methods
new(*args)
click to toggle source
# 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
Public Instance Methods
fields(*list)
click to toggle source
INSERT INTO … (FIELDS) VALUES (…)
# File lib/seaquel/ast/node.rb, line 71 def fields *list node(:fields, list) end
from(*tables)
click to toggle source
# File lib/seaquel/ast/node.rb, line 28 def from *tables node(:from, *tables) end
group_by(*fields)
click to toggle source
# File lib/seaquel/ast/node.rb, line 57 def group_by *fields node(:group_by, fields) end
having(*exps)
click to toggle source
# File lib/seaquel/ast/node.rb, line 54 def having *exps node(:having, exps) end
inspect()
click to toggle source
# File lib/seaquel/ast/node.rb, line 112 def inspect [type, args, parent].inspect end
into(table)
click to toggle source
# File lib/seaquel/ast/node.rb, line 91 def into table node(:into, table) end
join(*tables)
click to toggle source
# File lib/seaquel/ast/node.rb, line 40 def join *tables node(:join, tables) end
limit(n)
click to toggle source
# File lib/seaquel/ast/node.rb, line 47 def limit n node(:limit, n) end
node(*args)
click to toggle source
# File lib/seaquel/ast/node.rb, line 95 def node *args self.class.new(self, *args) end
offset(n)
click to toggle source
# File lib/seaquel/ast/node.rb, line 50 def offset n node(:offset, n) end
on(*exps)
click to toggle source
# File lib/seaquel/ast/node.rb, line 43 def on *exps node(:on, exps) end
order_by(*list)
click to toggle source
Replaces previous ORDER BY specification with this one.
@param list [Array<Column>] @return [Node] node for chaining
# File lib/seaquel/ast/node.rb, line 66 def order_by *list node(:order_by, list) end
project(*fields)
click to toggle source
Replaces previous projection list with this one.
@param list [Array<Column>] @return [Node] node for chaining
# File lib/seaquel/ast/node.rb, line 24 def project *fields node(:project, fields) end
set(*assign_list)
click to toggle source
# File lib/seaquel/ast/node.rb, line 36 def set *assign_list node(:set, assign_list) end
to_sql()
click to toggle source
# File lib/seaquel/ast/node.rb, line 108 def to_sql ::Seaquel::Generator.new(self).compact_sql end
values(*list)
click to toggle source
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)
@param list [Array<AST::Expression>] values to insert @return [AST::Node] query you are building
# File lib/seaquel/ast/node.rb, line 87 def values *list node(:values, list) end
visit(visitor)
click to toggle source
# 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
where(*exps)
click to toggle source
# File lib/seaquel/ast/node.rb, line 32 def where *exps node(:where, JoinOp.new(:and, exps)) end