forked from chuckpreslar/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_manager.go
More file actions
71 lines (60 loc) · 2.04 KB
/
insert_manager.go
File metadata and controls
71 lines (60 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package codex
// InsertManager manages a tree that compiles to a SQL insert statement.
type InsertManager struct {
Tree *InsertStatementNode // The AST for the SQL INSERT statement.
Adapter adapter // The SQL adapter.
}
// Appends the values to the trees Values node
func (self *InsertManager) Insert(values ...interface{}) *InsertManager {
self.Tree.Values.Expressions = append(self.Tree.Values.Expressions, values...)
return self
}
// Appends the columns to the trees Columns slice and Values node.
func (self *InsertManager) Into(columns ...interface{}) *InsertManager {
self.Tree.Values.Columns = append(self.Tree.Values.Columns, columns...)
self.Tree.Columns = append(self.Tree.Columns, columns...)
return self
}
// Return sets the InsertStatementNodes Return to the `column` paramenter
// after ensureing it is a ColumnNode.
func (self *InsertManager) Returning(column interface{}) *InsertManager {
if _, ok := column.(string); ok {
column = Column(column)
}
self.Tree.Returning = column
return self
}
// Selection returns a *SelectManager while keeping
// Table and adapter
func (self *InsertManager) Selection() *SelectManager {
m := Selection(self.Tree.Table)
m.Adapter = self.Adapter
return m
}
// Modification returns an *UpdateManager wwhile keeping
// Table and adapter
func (self *InsertManager) Modification() *UpdateManager {
m := Modification(self.Tree.Table)
m.Adapter = self.Adapter
return m
}
// Deletion returns a *DeleteManager while keeping
// Table and adapter
func (self *InsertManager) Deletion() *DeleteManager {
m := Deletion(self.Tree.Table)
m.Adapter = self.Adapter
return m
}
// ToSql calls a visitor's Accept method based on the manager's SQL adapter.
func (self *InsertManager) ToSql() (string, []interface{}, error) {
return VisitorFor(self.Adapter).Accept(self.Tree)
}
func (self *InsertManager) Table() *TableNode {
return self.Tree.Table
}
func Insertion(relation *TableNode) (m *InsertManager) {
m = new(InsertManager)
m.Tree = InsertStatement(relation)
m.Adapter = relation.Adapter
return
}