basis

package
v2.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSetter          = errors.New("setter is empty")
	ErrDataFormat        = errors.New("invalid data format")
	ErrUnsupportedDriver = errors.New("unsupported driver")
)
View Source
var (
	MinMapSize = 128
)

Functions

func DefaultModelTemplate

func DefaultModelTemplate() string

DefaultModelTemplate 默认模板

Types

type Column

type Column interface {
	Unsigned() bool
	Comment() string
	Field() string
	Name() string
	CanNull() bool
	Size() int
	Scale() int
	IsPrimaryKey() bool
	AutoIncrement() bool
	GoType() string
	Key() string
	Default() string
	Enums() []string
}

type Columns

type Columns []string

type Delete

type Delete func(table string, condition condition.Condition) (sql string, args []any)

type Executor

type Executor interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

type Flag

type Flag struct {
	// contains filtered or unexported fields
}

func ParseFlag

func ParseFlag() *Flag

func (*Flag) Charset

func (f *Flag) Charset() string

func (*Flag) Check

func (f *Flag) Check()

func (*Flag) DbName

func (f *Flag) DbName() string

func (*Flag) DriveName

func (f *Flag) DriveName() string

func (*Flag) Host

func (f *Flag) Host() string

func (*Flag) OutDir

func (f *Flag) OutDir() string

func (*Flag) Password

func (f *Flag) Password() string

func (*Flag) PkgName

func (f *Flag) PkgName() string

func (*Flag) Port

func (f *Flag) Port() uint32

func (*Flag) TemplateFile

func (f *Flag) TemplateFile() string

func (*Flag) UserName

func (f *Flag) UserName() string

type Generator

type Generator interface {
	Executor
	ShowTables(pattern string) (tables []string, err error)
	LoadTableSchema(table string) (t *Table, err error)
}

type Insert

type Insert func(table string, columns Columns, rows []Row, ignore bool) (sql string, args []any)

type MapSetter

type MapSetter map[string]any

func (MapSetter) Build

func (ms MapSetter) Build() (string, error)

type Mapping

type Mapping struct {
	// contains filtered or unexported fields
}

func ParseMapping

func ParseMapping(t any) *Mapping

func (*Mapping) Default

func (om *Mapping) Default(name string) string

func (*Mapping) Enums

func (om *Mapping) Enums(name string) []string

func (*Mapping) Field

func (om *Mapping) Field(name string) string

func (*Mapping) Index

func (om *Mapping) Index(name string) int

func (*Mapping) Kind

func (om *Mapping) Kind(name string) reflect.Kind

func (*Mapping) Label

func (om *Mapping) Label(name string) string

func (*Mapping) Name

func (om *Mapping) Name(field string) string

func (*Mapping) Names

func (om *Mapping) Names() []string

func (*Mapping) Size

func (om *Mapping) Size(name string) int

type Model

type Model interface {
	TableName() string
	PrimaryField() string
	PrimaryValue() any
	GetDefault(name string) string
	GetLabel(name string) string
	GetEnums(name string) []string
	GetSize(name string) int
	Query() Query
	Deleter() Delete
	Inserter() Insert
	Updater() Update
}

type Query

type Query interface {
	// Select Select表达式
	Select(columns ...string) Query
	// From From表达式
	From(table string) Query
	// 是否设置了table
	HasFrom() bool
	// Where where表达式
	Where(condition condition.Condition) Query
	// Group Group表达式
	Group(fields ...string) Query
	// Having Having表达式
	Having(having string) Query
	// Order Order表达式
	Order(orders ...string) Query
	// Offset Offset表达式
	Offset(offset int64) Query
	// Limit Limit表达式
	Limit(limit int64) Query
	// Sql 生成sql和参数
	Sql() (sql string, args []any)
	// Count 计数
	Count(field string) (sql string, args []any)
	// Sum 求和
	Sum(field string) (sql string, args []any)
	// Max 最大值
	Max(field string) (sql string, args []any)
	// Min 最小值
	Min(field string) (sql string, args []any)
	// Avg 平均值
	Avg(field string) (sql string, args []any)
	// Close 释放Query
	Close()
}

Query Query对象

type Record

type Record map[string]string

func ScanRecords

func ScanRecords(rows *sql.Rows) (records []Record, err error)

func (Record) Bool

func (r Record) Bool(key string) bool

func (Record) Bytes

func (r Record) Bytes(key string) []byte

func (Record) Convert

func (r Record) Convert(out any) (err error)

func (Record) Exists

func (r Record) Exists(key string) bool

func (Record) Float32

func (r Record) Float32(key string) float32

func (Record) Float64

func (r Record) Float64(key string) float64

func (Record) Int

func (r Record) Int(key string) int

func (Record) Int16

func (r Record) Int16(key string) int16

func (Record) Int32

func (r Record) Int32(key string) int32

func (Record) Int64

func (r Record) Int64(key string) int64

func (Record) Int8

func (r Record) Int8(key string) int8

func (Record) String

func (r Record) String(key string) string

func (Record) Uint

func (r Record) Uint(key string) uint

func (Record) Uint16

func (r Record) Uint16(key string) uint16

func (Record) Uint32

func (r Record) Uint32(key string) uint32

func (Record) Uint64

func (r Record) Uint64(key string) uint64

func (Record) Uint8

func (r Record) Uint8(key string) uint8

type Row

type Row []any

type Setter

type Setter interface {
	Build() (string, error)
}

type Stmt

type Stmt interface {
	ExecContext(ctx context.Context, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, args ...any) *sql.Row
}

type StringSetter

type StringSetter string

func (StringSetter) Build

func (ss StringSetter) Build() (string, error)

type Table

type Table struct {
	// contains filtered or unexported fields
}

func NewTable

func NewTable(name string, columns []Column) *Table

func (*Table) Columns

func (t *Table) Columns() []Column

func (*Table) GenerateCode

func (t *Table) GenerateCode(driverName, template, packageName string) string

func (*Table) Name

func (t *Table) Name() string

func (*Table) Primary

func (t *Table) Primary() Column

func (*Table) StructName

func (t *Table) StructName() string

type Tx

type Tx interface {
	Commit() error
	Rollback() error
}

type Update

type Update func(table, setters string, condition condition.Condition) (sql string, args []any)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL