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