Documentation
¶
Index ¶
- Constants
- Variables
- func BuildGroupBy(fields []string, dialect Dialect) string
- func BuildLimitOffset(q Query, startIndex int, dialect Dialect, args *[]Any) string
- func BuildOrderBy(q Query, dialect Dialect) string
- func CacheToken(name string, tables []string) string
- func CamelFieldPath(field string) string
- func EmitMutation(base, table, op string, rows int64, key Any, data Map, where Map)
- func Error(op string, code error, err error) error
- func ErrorKind(err error) string
- func Field(name string, field string, extends ...Any) Var
- func Fields(name string, keys []string, extends ...Vars) Vars
- func GenerateTableKeys(tableName string, table Table) string
- func Migrate(names ...string) error
- func MigrateDown(steps int) error
- func MigrateDownOn(base string, steps int) error
- func MigrateOn(base string, names ...string) error
- func MigrateUp(versions ...string) error
- func MigrateUpOn(base string, versions ...string) error
- func Models() map[string]Model
- func Option(name string, field string, key string) Any
- func Options(name string, field string) Map
- func QuerySignature(q Query) string
- func RegisterConfig(name string, cfg Config)
- func RegisterDeleteWatcher(name string, watcher DeleteWatcher)
- func RegisterDriver(name string, driver Driver)
- func RegisterInsertWatcher(name string, watcher InsertWatcher)
- func RegisterMigration(name string, migration Migration)
- func RegisterModel(name string, model Model)
- func RegisterTable(name string, table Table)
- func RegisterUpdateWatcher(name string, watcher UpdateWatcher)
- func RegisterUpsertWatcher(name string, watcher UpsertWatcher)
- func RegisterView(name string, view View)
- func RegisterWatcher(name string, watcher Watcher)
- func RegisterWatchers(items Watchers)
- func SnakeFieldPath(field string) string
- func Tables() map[string]Table
- func TouchTableCache(name, table string) uint64
- func Views() map[string]View
- type Agg
- type AndExpr
- type Capabilities
- type CmpExpr
- type Config
- type Configs
- type Connection
- type DataBase
- type DataError
- type DataModel
- type DataTable
- type DataView
- type DeleteWatcher
- type Dialect
- type Driver
- type ExistsExpr
- type Expr
- type FieldRef
- type Health
- type Index
- type InsertWatcher
- type Instance
- type Join
- type MigrateAction
- type MigrateOptions
- type MigrateReport
- type Migration
- type Model
- type Module
- func (m *Module) Base(names ...string) DataBase
- func (m *Module) Close()
- func (m *Module) Config(global Map)
- func (m *Module) Field(name, field string, extends ...Any) Var
- func (m *Module) Fields(name string, keys []string, extends ...Vars) Vars
- func (m *Module) GetCapabilities(names ...string) (Capabilities, error)
- func (m *Module) ModelConfig(name string) *Model
- func (m *Module) Models() map[string]Model
- func (m *Module) Open()
- func (m *Module) Option(name, field, key string) Any
- func (m *Module) Options(name, field string) Map
- func (m *Module) PoolStats(names ...string) []PoolStats
- func (m *Module) Register(name string, value Any)
- func (m *Module) RegisterConfig(name string, cfg Config)
- func (m *Module) RegisterConfigs(configs Configs)
- func (m *Module) RegisterDeleteWatcher(name string, watcher DeleteWatcher)
- func (m *Module) RegisterDriver(name string, driver Driver)
- func (m *Module) RegisterInsertWatcher(name string, watcher InsertWatcher)
- func (m *Module) RegisterMigration(name string, migration Migration)
- func (m *Module) RegisterModel(name string, model Model)
- func (m *Module) RegisterTable(name string, table Table)
- func (m *Module) RegisterUpdateWatcher(name string, watcher UpdateWatcher)
- func (m *Module) RegisterUpsertWatcher(name string, watcher UpsertWatcher)
- func (m *Module) RegisterView(name string, view View)
- func (m *Module) RegisterWatcher(name string, watcher Watcher)
- func (m *Module) RegisterWatchers(items Watchers)
- func (m *Module) Setup()
- func (m *Module) Start()
- func (m *Module) Stats(names ...string) Stats
- func (m *Module) Stop()
- func (m *Module) TableConfig(name string) *Table
- func (m *Module) Tables() map[string]Table
- func (m *Module) ViewConfig(name string) *View
- func (m *Module) Views() map[string]View
- type Mutation
- type NotExpr
- type NullExpr
- type OrExpr
- type PlanOptions
- type PoolStats
- type Query
- type RawExpr
- type SQLBuilder
- type ScanFunc
- type Sort
- type Stats
- type Table
- type TrueExpr
- type TxFunc
- type UpdateWatcher
- type UpsertWatcher
- type View
- type Watcher
- type Watchers
Constants ¶
View Source
const ( MutationInsert = "insert" MutationUpdate = "update" MutationDelete = "delete" MutationUpsert = "upsert" )
View Source
const NAME = "DATA"
Variables ¶
View Source
var ( ErrNotFound = errors.New("data: not found") ErrConflict = errors.New("data: conflict") ErrUnsupported = errors.New("data: unsupported") ErrInvalidQuery = errors.New("data: invalid query") ErrInvalidUpdate = errors.New("data: invalid update") ErrTxFailed = errors.New("data: tx failed") ErrValidation = errors.New("data: validation") ErrDriver = errors.New("data: driver") ErrTimeout = errors.New("data: timeout") )
Functions ¶
func BuildGroupBy ¶
func BuildLimitOffset ¶
func BuildOrderBy ¶
func CacheToken ¶ added in v0.3.0
func CamelFieldPath ¶ added in v0.2.0
func EmitMutation ¶ added in v0.3.0
func GenerateTableKeys ¶ added in v0.1.1
GenerateTableKeys emits a compact Go constant block for table field names. It helps projects avoid manual string literals in query/update code.
func MigrateDown ¶ added in v0.2.0
func MigrateDownOn ¶ added in v0.2.0
func MigrateUpOn ¶ added in v0.2.0
func QuerySignature ¶ added in v0.3.0
func RegisterConfig ¶
func RegisterDeleteWatcher ¶ added in v0.3.0
func RegisterDeleteWatcher(name string, watcher DeleteWatcher)
func RegisterDriver ¶
func RegisterInsertWatcher ¶ added in v0.3.0
func RegisterInsertWatcher(name string, watcher InsertWatcher)
func RegisterMigration ¶ added in v0.2.0
func RegisterModel ¶
func RegisterTable ¶
func RegisterUpdateWatcher ¶ added in v0.3.0
func RegisterUpdateWatcher(name string, watcher UpdateWatcher)
func RegisterUpsertWatcher ¶ added in v0.3.0
func RegisterUpsertWatcher(name string, watcher UpsertWatcher)
func RegisterView ¶
func RegisterWatcher ¶ added in v0.3.0
func RegisterWatchers ¶ added in v0.3.0
func RegisterWatchers(items Watchers)
func SnakeFieldPath ¶ added in v0.2.0
func TouchTableCache ¶ added in v0.3.0
Types ¶
type Capabilities ¶
type Capabilities struct {
Dialect string `json:"dialect"`
ILike bool `json:"ilike"`
Returning bool `json:"returning"`
Join bool `json:"join"`
Group bool `json:"group"`
Having bool `json:"having"`
Aggregate bool `json:"aggregate"`
KeysetAfter bool `json:"keyset_after"`
JsonContains bool `json:"json_contains"`
ArrayOverlap bool `json:"array_overlap"`
JsonElemMatch bool `json:"json_elem_match"`
}
func GetCapabilities ¶
func GetCapabilities(names ...string) (Capabilities, error)
type Connection ¶
type DataBase ¶
type DataBase interface {
Close() error
WithContext(context.Context) DataBase
WithTimeout(time.Duration) DataBase
Begin() error
Commit() error
Rollback() error
Tx(TxFunc) error
TxReadOnly(TxFunc) error
Migrate(...string)
MigratePlan(...string) MigrateReport
MigrateDiff(...string) MigrateReport
MigrateUp(...string)
MigrateDown(int)
MigrateTo(string)
MigrateDownTo(string)
Capabilities() Capabilities
Error() error
ClearError()
Table(string) DataTable
View(string) DataView
Model(string) DataModel
Raw(string, ...Any) []Map
Exec(string, ...Any) int64
Parse(...Any) (string, []Any)
}
type DataTable ¶
type DataTable interface {
Insert(Map) Map
InsertMany([]Map) []Map
Upsert(Map, ...Any) Map
UpsertMany([]Map, ...Any) []Map
Change(Map, Map) Map
Remove(...Any) Map
Update(Map, ...Any) int64
Delete(...Any) int64
Entity(Any) Map
Count(...Any) int64
Aggregate(...Any) []Map
First(...Any) Map
Query(...Any) []Map
Scan(ScanFunc, ...Any) Res
ScanN(int64, ScanFunc, ...Any) Res
Slice(offset, limit int64, args ...Any) (int64, []Map)
Group(field string, args ...Any) []Map
}
type DeleteWatcher ¶ added in v0.3.0
type Driver ¶
type Driver interface {
Connect(*Instance) (Connection, error)
}
type ExistsExpr ¶
type InsertWatcher ¶ added in v0.3.0
type MigrateAction ¶ added in v0.2.0
type MigrateOptions ¶ added in v0.2.0
type MigrateReport ¶ added in v0.2.0
type MigrateReport struct {
Mode string `json:"mode"`
DryRun bool `json:"dryRun"`
Actions []MigrateAction `json:"actions"`
}
func MigrateDiff ¶ added in v0.2.0
func MigrateDiff(names ...string) (MigrateReport, error)
func MigrateDiffOn ¶ added in v0.2.0
func MigrateDiffOn(base string, names ...string) (MigrateReport, error)
func MigratePlan ¶ added in v0.2.0
func MigratePlan(names ...string) (MigrateReport, error)
func MigratePlanOn ¶ added in v0.2.0
func MigratePlanOn(base string, names ...string) (MigrateReport, error)
type Migration ¶ added in v0.2.0
type Migration struct {
Version string
Name string
Desc string
Up func(DataBase) error
Down func(DataBase) error
}
func Migrations ¶ added in v0.2.0
type Model ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
func (*Module) GetCapabilities ¶
func (m *Module) GetCapabilities(names ...string) (Capabilities, error)
func (*Module) ModelConfig ¶ added in v0.5.0
func (*Module) RegisterConfig ¶
func (*Module) RegisterConfigs ¶
func (*Module) RegisterDeleteWatcher ¶ added in v0.3.0
func (m *Module) RegisterDeleteWatcher(name string, watcher DeleteWatcher)
func (*Module) RegisterDriver ¶
func (*Module) RegisterInsertWatcher ¶ added in v0.3.0
func (m *Module) RegisterInsertWatcher(name string, watcher InsertWatcher)
func (*Module) RegisterMigration ¶ added in v0.2.0
func (*Module) RegisterModel ¶
func (*Module) RegisterTable ¶
func (*Module) RegisterUpdateWatcher ¶ added in v0.3.0
func (m *Module) RegisterUpdateWatcher(name string, watcher UpdateWatcher)
func (*Module) RegisterUpsertWatcher ¶ added in v0.3.0
func (m *Module) RegisterUpsertWatcher(name string, watcher UpsertWatcher)
func (*Module) RegisterView ¶
func (*Module) RegisterWatcher ¶ added in v0.3.0
func (*Module) RegisterWatchers ¶ added in v0.3.0
func (*Module) TableConfig ¶ added in v0.5.0
func (*Module) ViewConfig ¶ added in v0.5.0
type PlanOptions ¶ added in v0.2.0
type PoolStats ¶ added in v0.3.0
type PoolStats struct {
Name string `json:"name"`
Driver string `json:"driver"`
Open int `json:"open"`
InUse int `json:"inUse"`
Idle int `json:"idle"`
WaitCount int64 `json:"waitCount"`
WaitDuration int64 `json:"waitDurationMs"`
MaxOpen int `json:"maxOpen"`
Queries int64 `json:"queries"`
Writes int64 `json:"writes"`
Errors int64 `json:"errors"`
CacheHit int64 `json:"cacheHit"`
CacheRate float64 `json:"cacheRate"`
Slow int64 `json:"slow"`
SlowAvgMs int64 `json:"slowAvgMs"`
SlowP50Ms int64 `json:"slowP50Ms"`
SlowP95Ms int64 `json:"slowP95Ms"`
}
func GetPoolStats ¶ added in v0.3.0
type Query ¶
type Query struct {
Select []string
Filter Expr
Sort []Sort
Limit int64
Offset int64
After Map
WithCount bool
Unsafe bool
Batch int64
Group []string
Aggs []Agg
Having Expr
Joins []Join
RawWhere string
RawParams []Any
}
func ParseQuery ¶
type SQLBuilder ¶
type SQLBuilder struct {
// contains filtered or unexported fields
}
func NewSQLBuilder ¶
func NewSQLBuilder(d Dialect) *SQLBuilder
func (*SQLBuilder) Args ¶
func (b *SQLBuilder) Args() []Any
func (*SQLBuilder) CompileExpr ¶
func (b *SQLBuilder) CompileExpr(e Expr) (string, error)
func (*SQLBuilder) CompileWhere ¶
func (b *SQLBuilder) CompileWhere(q Query) (string, []Any, error)
type Stats ¶
type Stats struct {
Queries int64 `json:"queries"`
Writes int64 `json:"writes"`
Errors int64 `json:"errors"`
Slow int64 `json:"slow"`
CacheHit int64 `json:"cacheHit"`
CacheRate float64 `json:"cacheRate"`
SlowAvgMs int64 `json:"slowAvgMs"`
SlowP50Ms int64 `json:"slowP50Ms"`
SlowP95Ms int64 `json:"slowP95Ms"`
ChangeIn int64 `json:"changeIn"`
ChangeDrop int64 `json:"changeDrop"`
ChangeFail int64 `json:"changeFail"`
}
type Table ¶
type UpdateWatcher ¶ added in v0.3.0
type UpsertWatcher ¶ added in v0.3.0
type View ¶
Click to show internal directories.
Click to hide internal directories.