Skip to content

Commit 733a530

Browse files
committed
Introduce database#InsertStatement
1 parent 140c2f0 commit 733a530

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

database/statements.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package database
2+
3+
type InsertStatement interface {
4+
Into(table string) InsertStatement
5+
6+
SetColumns(columns ...string) InsertStatement
7+
8+
SetExcludedColumns(columns ...string) InsertStatement
9+
10+
Entity() Entity
11+
12+
Table() string
13+
14+
Columns() []string
15+
16+
ExcludedColumns() []string
17+
}
18+
19+
func NewInsert(entity Entity) InsertStatement {
20+
return &insertStatement{
21+
entity: entity,
22+
}
23+
}
24+
25+
type insertStatement struct {
26+
entity Entity
27+
table string
28+
columns []string
29+
excludedColumns []string
30+
}
31+
32+
func (i *insertStatement) Into(table string) InsertStatement {
33+
i.table = table
34+
35+
return i
36+
}
37+
38+
func (i *insertStatement) SetColumns(columns ...string) InsertStatement {
39+
i.columns = columns
40+
41+
return i
42+
}
43+
44+
func (i *insertStatement) SetExcludedColumns(columns ...string) InsertStatement {
45+
i.excludedColumns = columns
46+
47+
return i
48+
}
49+
50+
func (i *insertStatement) Entity() Entity {
51+
return i.entity
52+
}
53+
54+
func (i *insertStatement) Table() string {
55+
return i.table
56+
}
57+
58+
func (i *insertStatement) Columns() []string {
59+
return i.columns
60+
}
61+
62+
func (i *insertStatement) ExcludedColumns() []string {
63+
return i.excludedColumns
64+
}

0 commit comments

Comments
 (0)