Documentation ¶
Index ¶
- Constants
- Variables
- func DeserializeField(t uint8, data string, v *interface{})
- func PrepareStmt(db *DB, query string) *sql.Stmt
- func SerializeField(t uint8, data interface{}) interface{}
- type Config
- type DB
- type Entity
- func (ent *Entity[T]) Select(ctx context.Context, where string, args ...any) ([]*T, error)
- func (ent *Entity[T]) SelectOne(ctx context.Context, where string, args ...any) (*T, error)
- func (ent *Entity[T]) SelectPage(ctx context.Context, page_idx, page_size int64, where string, args ...any) ([]*T, int64, int64, int64, int64, error)
- type Field
- type FieldIndexDecl
- type Index
- type Schema
- func (sc *Schema[T]) Columns() []string
- func (sc *Schema[T]) Count(ctx context.Context, where string, args ...any) (int64, error)
- func (sc *Schema[T]) Delete(ctx context.Context, where string, args ...any) (int64, error)
- func (sc *Schema[T]) Field(name string) *Field
- func (sc *Schema[T]) Index(name string) *Index
- func (sc *Schema[T]) Insert(ctx context.Context, data *T) error
- func (sc *Schema[T]) Select(ctx context.Context, where string, args ...any) ([]*T, error)
- func (sc *Schema[T]) SelectOne(ctx context.Context, where string, args ...any) (*T, error)
- func (sc *Schema[T]) SelectPage(ctx context.Context, page_idx, page_size int64, where string, args ...any) ([]*T, int64, int64, int64, int64, error)
- func (sc *Schema[T]) Update(ctx context.Context, data *T, columns ...string) (int64, error)
Constants ¶
View Source
const ( // NONE for None NONE = 0 // Serialize Types JSON = 2 YAML = 3 // Index Types INDEX = 1 UNIQUE = 2 PRIMARY_KEY = 3 )
Variables ¶
View Source
var ( ErrInvalidData = errors.New("invalid data") ErrNotFound = errors.New("not found") ErrNoDataInfo = errors.New("dataInfo is missing, call Reflect on Schema first") ErrNotReady = errors.New("stmtInsert is not ready, call Prepare on Schema first") ErrNoPrimaryKey = errors.New("no primary key") ErrNoRowsAffected = errors.New("no rows affected") ErrDuplicateKey = errors.New("duplicate key") )
Functions ¶
func DeserializeField ¶ added in v0.1.0
func SerializeField ¶ added in v0.1.0
func SerializeField(t uint8, data interface{}) interface{}
Types ¶
type Config ¶
type Config struct { Addr string `mapstructure:"address" json:"address" yaml:"address"` Username string `mapstructure:"username" json:"username" yaml:"username"` Password string `mapstructure:"password" json:"password" yaml:"password"` DataBase string `mapstructure:"database" json:"database" yaml:"database"` }
type Entity ¶ added in v0.1.0
type Entity[T interface{}] struct {
// contains filtered or unexported fields
}
func (*Entity[T]) SelectPage ¶ added in v0.1.0
func (ent *Entity[T]) SelectPage(ctx context.Context, page_idx, page_size int64, where string, args ...any) ([]*T, int64, int64, int64, int64, error)
SelectPage selects a page of records from the database. page_idx shoud be 1-based. Return: records, current page index, page size, page_count, total count, error
type Field ¶
type Field struct { // Basic information Name string // Column name Type string // Column type in SQL format IsPrimaryKey bool IsAutoIncrement bool IsNullable bool IsUnsigned bool DefaultValue string // Default value in SQL format Comment string SerializeMethod uint8 // json | yaml | none Indices []*FieldIndexDecl EntityIndex int // Index in the entity }
func (*Field) CompleteWithType ¶ added in v0.1.0
func (fd *Field) CompleteWithType(structField reflect.StructField)
type FieldIndexDecl ¶ added in v0.1.0
type Schema ¶
type Schema[T interface{}] struct { Name string Fields []*Field Indices []*Index Engine string Collate string Comment string FieldsByColumn map[string]*Field // contains filtered or unexported fields }
func (*Schema[T]) SelectPage ¶ added in v0.1.2
func (sc *Schema[T]) SelectPage(ctx context.Context, page_idx, page_size int64, where string, args ...any) ([]*T, int64, int64, int64, int64, error)
SelectPage selects a page of records from the database. page_idx shoud be 1-based. Return: records, current page index, page size, page count, total count, error
Source Files ¶
- config.go
- db.go
- entity.go
- entity.select.go
- error.go
- escape_sql.go
- helper.go
- index.go
- misc.go
- schema.count.go
- schema.dbopt.go
- schema.delete.go
- schema.field.fromTag.go
- schema.field.go
- schema.fromType.go
- schema.go
- schema.insert.go
- schema.new.go
- schema.select.go
- schema.update.go
- schema.utils.go
- serialize.go
Click to show internal directories.
Click to hide internal directories.