-
Notifications
You must be signed in to change notification settings - Fork 1
/
expr.go
64 lines (51 loc) · 1.17 KB
/
expr.go
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
package genorm
type Expr interface {
Expr() (string, []ExprType, []error)
}
type TableExpr[T Table] interface {
Expr
TableExpr(T) (string, []ExprType, []error)
}
type TypedExpr[T ExprType] interface {
Expr
TypedExpr(T) (string, []ExprType, []error)
}
type TypedTableExpr[T Table, S ExprType] interface {
Expr
TableExpr[T]
TypedExpr[S]
}
type TableAssignExpr[T Table] struct {
query string
args []ExprType
errs []error
}
func (tae *TableAssignExpr[_]) AssignExpr() (string, []ExprType, []error) {
if len(tae.errs) != 0 {
return "", nil, tae.errs
}
return tae.query, tae.args, nil
}
type ExprStruct[T Table, S ExprType] struct {
query string
args []ExprType
errs []error
}
func RawExpr[T Table, S ExprType](query string, args ...ExprType) *ExprStruct[T, S] {
return &ExprStruct[T, S]{
query: query,
args: args,
}
}
func (es *ExprStruct[_, _]) Expr() (string, []ExprType, []error) {
if len(es.errs) != 0 {
return "", nil, es.errs
}
return es.query, es.args, nil
}
func (es *ExprStruct[T, _]) TableExpr(T) (string, []ExprType, []error) {
return es.Expr()
}
func (es *ExprStruct[_, S]) TypedExpr(S) (string, []ExprType, []error) {
return es.Expr()
}