Documentation
¶
Index ¶
- Constants
- Variables
- type AlterTablePlan
- type AuthenticatedUser
- type CascadeInclude
- type CascadeQuery
- type Column
- type DB
- func (db *DB) AlterTable(plan AlterTablePlan) error
- func (db *DB) AutoMigrate(schema TableSchema) error
- func (db *DB) BeginReadOnlyTx() (*Tx, error)
- func (db *DB) BeginTx() (*Tx, error)
- func (db *DB) BeginTxWithOptions(options TxOptions) (*Tx, error)
- func (db *DB) Close() error
- func (db *DB) Compact() error
- func (db *DB) Configure(schema TableSchema) error
- func (db *DB) CreateTable(schema TableSchema) error
- func (db *DB) Delete(key string) error
- func (db *DB) DeleteRow(primaryKey any) error
- func (db *DB) DeleteRows(primaryKeys []any) error
- func (db *DB) DropTable() error
- func (db *DB) Find(conditions ...QueryCondition) ([]Row, error)
- func (db *DB) FindByConditions(conditions []QueryCondition) ([]Row, error)
- func (db *DB) FindOne(conditions ...QueryCondition) (Row, bool, error)
- func (db *DB) FindRow(primaryKey any) (Row, bool, error)
- func (db *DB) Get(key string) ([]byte, bool, error)
- func (db *DB) GetConfig() DatabaseConfig
- func (db *DB) GetSchema() (*TableSchema, error)
- func (db *DB) HasSchema() bool
- func (db *DB) InsertRow(values Row) (Row, error)
- func (db *DB) InsertRows(values []Row) ([]Row, error)
- func (db *DB) Keys() ([]string, error)
- func (db *DB) Put(key string, value []byte) error
- func (db *DB) Query(prefix string) (map[string][]byte, error)
- func (db *DB) QueryCascade(query CascadeQuery) ([]map[string]any, error)
- func (db *DB) QueryCascadeJSON(query CascadeQuery) ([]byte, error)
- func (db *DB) RemoveByCondition(conditions ...QueryCondition) (int, error)
- func (db *DB) RemoveOneByCondition(conditions ...QueryCondition) (bool, error)
- func (db *DB) SchemaDiff(target TableSchema) (*AlterTablePlan, bool, error)
- func (db *DB) SetAttrs(attrs ...kernal.SchemaAttributer) *DB
- func (db *DB) SyncSchema(schema TableSchema) error
- func (db *DB) TruncateTable() error
- func (db *DB) Update(key string, value []byte) error
- func (db *DB) UpdateRow(primaryKey any, updates Row) (Row, error)
- func (db *DB) UpdateRows(updates []RowUpdate) ([]Row, error)
- func (db *DB) WithTx(fn func(tx *Tx) error) error
- type DatabaseConfig
- type DriverError
- type ErrorCode
- type ForeignKey
- type QueryCondition
- type Row
- type RowUpdate
- type TableAccessGrant
- type TableAccessScope
- type TableSchema
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) Delete(key string) error
- func (tx *Tx) DeleteRow(primaryKey any) error
- func (tx *Tx) DeleteRows(primaryKeys []any) error
- func (tx *Tx) Find(conditions ...QueryCondition) ([]Row, error)
- func (tx *Tx) FindByConditions(conditions []QueryCondition) ([]Row, error)
- func (tx *Tx) FindOne(conditions ...QueryCondition) (Row, bool, error)
- func (tx *Tx) FindRow(primaryKey any) (Row, bool, error)
- func (tx *Tx) Get(key string) ([]byte, bool, error)
- func (tx *Tx) InsertRow(values Row) (Row, error)
- func (tx *Tx) InsertRows(values []Row) ([]Row, error)
- func (tx *Tx) Keys() ([]string, error)
- func (tx *Tx) Put(key string, value []byte) error
- func (tx *Tx) Query(prefix string) (map[string][]byte, error)
- func (tx *Tx) RemoveByCondition(conditions ...QueryCondition) (int, error)
- func (tx *Tx) RemoveOneByCondition(conditions ...QueryCondition) (bool, error)
- func (tx *Tx) Rollback() error
- func (tx *Tx) UpdateRow(primaryKey any, updates Row) (Row, error)
- func (tx *Tx) UpdateRows(updates []RowUpdate) ([]Row, error)
- type TxIsolation
- type TxOptions
Constants ¶
View Source
const ( TableAccessScopeDML = kernal.TableAccessScopeDML TableAccessScopeDDL = kernal.TableAccessScopeDDL )
View Source
const ( QueryOpEQ = kernal.QueryOpEQ QueryOpNE = kernal.QueryOpNE QueryOpGT = kernal.QueryOpGT QueryOpGTE = kernal.QueryOpGTE QueryOpLT = kernal.QueryOpLT QueryOpLTE = kernal.QueryOpLTE QueryOpIn = kernal.QueryOpIn QueryOpNotIn = kernal.QueryOpNotIn QueryOpBetween = kernal.QueryOpBetween QueryOpNotBetween = kernal.QueryOpNotBetween )
Variables ¶
View Source
var New app
Functions ¶
This section is empty.
Types ¶
type AlterTablePlan ¶
type AlterTablePlan = kernal.AlterTablePlan
type AuthenticatedUser ¶
type AuthenticatedUser = kernal.AuthenticatedUser
type CascadeInclude ¶
type CascadeInclude = kernal.CascadeInclude
type CascadeQuery ¶
type CascadeQuery = kernal.CascadeQuery
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) AlterTable ¶
func (db *DB) AlterTable(plan AlterTablePlan) error
AlterTable 按 AlterTablePlan 修改表结构(AddColumn/DropColumn/AddIndex 等)。
func (*DB) AutoMigrate ¶
func (db *DB) AutoMigrate(schema TableSchema) error
AutoMigrate 保守迁移:无表则建,有表则只**增**列/索引,绝不删除(幂等安全)。
func (*DB) BeginReadOnlyTx ¶
func (*DB) Configure ¶
func (db *DB) Configure(schema TableSchema) error
func (*DB) CreateTable ¶
func (db *DB) CreateTable(schema TableSchema) error
CreateTable 以严格 DDL 语义创建表结构,若已存在 Schema 则返回错误。
func (*DB) DeleteRows ¶
func (*DB) FindByConditions ¶
func (db *DB) FindByConditions(conditions []QueryCondition) ([]Row, error)
func (*DB) GetConfig ¶
func (db *DB) GetConfig() DatabaseConfig
func (*DB) GetSchema ¶
func (db *DB) GetSchema() (*TableSchema, error)
func (*DB) QueryCascade ¶
func (db *DB) QueryCascade(query CascadeQuery) ([]map[string]any, error)
func (*DB) QueryCascadeJSON ¶
func (db *DB) QueryCascadeJSON(query CascadeQuery) ([]byte, error)
func (*DB) RemoveByCondition ¶
func (db *DB) RemoveByCondition(conditions ...QueryCondition) (int, error)
func (*DB) RemoveOneByCondition ¶
func (db *DB) RemoveOneByCondition(conditions ...QueryCondition) (bool, error)
func (*DB) SchemaDiff ¶
func (db *DB) SchemaDiff(target TableSchema) (*AlterTablePlan, bool, error)
SchemaDiff 计算从当前 Schema 到目标 Schema 的迁移计划,不执行任何变更。 返回值:(plan, schemaExists, error)
- plan == nil && !schemaExists → 当前无 Schema,需调用 CreateTable
- plan == nil && schemaExists → Schema 已与目标一致,无需变更
- plan != nil → 有差异,plan 描述所需变更
func (*DB) SyncSchema ¶
func (db *DB) SyncSchema(schema TableSchema) error
SyncSchema 完全同步:无表则建,有差异则全量同步(含删列,⚠️ 不可逆)。
type DatabaseConfig ¶
type DatabaseConfig = kernal.DatabaseConfig
type DriverError ¶
func (*DriverError) Error ¶
func (e *DriverError) Error() string
func (*DriverError) Unwrap ¶
func (e *DriverError) Unwrap() error
type ErrorCode ¶
type ErrorCode string
const ( ErrorCodeInvalidArgument ErrorCode = "invalid_argument" ErrorCodeNotFound ErrorCode = "not_found" ErrorCodeConflict ErrorCode = "conflict" ErrorCodeClosed ErrorCode = "closed" ErrorCodeReadOnly ErrorCode = "read_only" ErrorCodeDDL ErrorCode = "ddl_error" ErrorCodeInternal ErrorCode = "internal" )
type ForeignKey ¶
type ForeignKey = kernal.ForeignKey
type QueryCondition ¶
type QueryCondition = kernal.QueryCondition
type TableAccessGrant ¶
type TableAccessGrant = kernal.TableAccessGrant
type TableAccessScope ¶
type TableAccessScope = kernal.TableAccessScope
type TableSchema ¶
type TableSchema = kernal.TableSchema
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
func (*Tx) DeleteRows ¶
func (*Tx) FindByConditions ¶
func (tx *Tx) FindByConditions(conditions []QueryCondition) ([]Row, error)
func (*Tx) RemoveByCondition ¶
func (tx *Tx) RemoveByCondition(conditions ...QueryCondition) (int, error)
func (*Tx) RemoveOneByCondition ¶
func (tx *Tx) RemoveOneByCondition(conditions ...QueryCondition) (bool, error)
type TxIsolation ¶
type TxIsolation string
const ( TxIsolationSnapshot TxIsolation = "snapshot" TxIsolationReadCommitted TxIsolation = "read_committed" )
type TxOptions ¶
type TxOptions struct {
ReadOnly bool
Isolation TxIsolation
}
Click to show internal directories.
Click to hide internal directories.