2023-01-12 12:42:16 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ ParseWhere = SqlBuilder{}
|
|
|
|
var globalBb dbQuery
|
|
|
|
|
|
|
|
func InitDB(db dbQuery) {
|
|
|
|
globalBb = db
|
|
|
|
}
|
|
|
|
|
2023-02-10 13:23:30 +00:00
|
|
|
type QueryFn func(context.Context, any, string, ...any) error
|
|
|
|
|
2023-01-12 12:42:16 +00:00
|
|
|
type Model interface {
|
|
|
|
PrimaryKey() string
|
|
|
|
Table() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ParseWhere interface {
|
|
|
|
ParseWhere(*[][]any) (string, []any, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type dbQuery interface {
|
|
|
|
Select(context.Context, any, string, ...any) error
|
|
|
|
Get(context.Context, any, string, ...any) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type SqlBuilder [][]string
|
2023-02-25 15:38:12 +00:00
|
|
|
|
|
|
|
func Table[T Model]() string {
|
|
|
|
var r T
|
|
|
|
return r.Table()
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrimaryKey[T Model]() string {
|
|
|
|
var r T
|
|
|
|
return r.PrimaryKey()
|
|
|
|
}
|