Skip to content

Commit 647d090

Browse files
committed
Introduce database#SelectStatement
1 parent c2b3877 commit 647d090

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

database/statements.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,82 @@ func (i *insertStatement) Columns() []string {
6262
func (i *insertStatement) ExcludedColumns() []string {
6363
return i.excludedColumns
6464
}
65+
66+
type SelectStatement interface {
67+
From(table string) SelectStatement
68+
69+
SetColumns(columns ...string) SelectStatement
70+
71+
SetExcludedColumns(columns ...string) SelectStatement
72+
73+
SetWhere(where string) SelectStatement
74+
75+
Entity() Entity
76+
77+
Table() string
78+
79+
Columns() []string
80+
81+
ExcludeColumns() []string
82+
83+
Where() string
84+
}
85+
86+
func NewSelect(entity Entity) SelectStatement {
87+
return &selectStatement{
88+
entity: entity,
89+
}
90+
}
91+
92+
type selectStatement struct {
93+
entity Entity
94+
table string
95+
columns []string
96+
excludedColumns []string
97+
where string
98+
whereValues []any
99+
}
100+
101+
func (s *selectStatement) From(table string) SelectStatement {
102+
s.table = table
103+
104+
return s
105+
}
106+
107+
func (s *selectStatement) SetColumns(columns ...string) SelectStatement {
108+
s.columns = columns
109+
110+
return s
111+
}
112+
113+
func (s *selectStatement) SetExcludedColumns(columns ...string) SelectStatement {
114+
s.excludedColumns = columns
115+
116+
return s
117+
}
118+
119+
func (s *selectStatement) SetWhere(where string) SelectStatement {
120+
s.where = where
121+
122+
return s
123+
}
124+
125+
func (s *selectStatement) Entity() Entity {
126+
return s.entity
127+
}
128+
129+
func (s *selectStatement) Table() string {
130+
return s.table
131+
}
132+
133+
func (s *selectStatement) Columns() []string {
134+
return s.columns
135+
}
136+
137+
func (s *selectStatement) ExcludeColumns() []string {
138+
return s.excludedColumns
139+
}
140+
141+
func (s *selectStatement) Where() string {
142+
return s.where
143+
}

0 commit comments

Comments
 (0)