orm

package
v0.1.68 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRows = errs.ErrNoRows
)

Functions

This section is empty.

Types

type Aggregate added in v0.1.25

type Aggregate struct {
	Fn    string
	Arg   string
	Alias string
}

Aggregate 聚合函数

func Avg added in v0.1.25

func Avg(col string) Aggregate

func (Aggregate) As added in v0.1.25

func (a Aggregate) As(alias string) Aggregate

func (Aggregate) Eq added in v0.1.26

func (a Aggregate) Eq(arg any) Predicate

func (Aggregate) GT added in v0.1.26

func (a Aggregate) GT(arg any) Predicate

func (Aggregate) LT added in v0.1.26

func (a Aggregate) LT(arg any) Predicate

func (Aggregate) Select added in v0.1.25

func (a Aggregate) Select()

type Assignable added in v0.1.25

type Assignable interface {
	Assign()
}

Assignable 可用于update语句的SET,ON DUPLICATE KEY UPDATE后

type Assignment added in v0.1.25

type Assignment struct {
	Column string
	Val    any
}

func Assign added in v0.1.25

func Assign(col string, val any) Assignment

func (Assignment) Assign added in v0.1.25

func (Assignment) Assign()

type Column

type Column struct {
	Name  string
	Alias string         // 别名
	Table TableReference // table
}

func C

func C(columnName string) Column

func (Column) As added in v0.1.25

func (c Column) As(alias string) Column

func (Column) Assign added in v0.1.25

func (Column) Assign()

func (Column) Eq

func (c Column) Eq(val any) Predicate

func (Column) LT added in v0.1.24

func (c Column) LT(val any) Predicate

func (Column) Plus added in v0.1.25

func (c Column) Plus(val any) Predicate

func (Column) Select added in v0.1.25

func (c Column) Select()

type DB

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

func MustNewDB

func MustNewDB(driveName string, dataSourceName string, opts ...DBOption) *DB

func Open added in v0.1.24

func Open(driveName string, dataSourceName string, opts ...DBOption) (*DB, error)

func OpenDB added in v0.1.24

func OpenDB(sqlDB *sql.DB, opts ...DBOption) (*DB, error)

func (*DB) BeginTx added in v0.1.26

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

func (*DB) DoTx added in v0.1.26

func (db *DB) DoTx(context context.Context, fn func(ctx context.Context, tx *Tx) error, opts *sql.TxOptions) (err error)

func (*DB) Wait added in v0.1.36

func (db *DB) Wait() error

type DBOption

type DBOption func(db *DB)

func DBWithCreator added in v0.1.24

func DBWithCreator(creator valuer.Creator) DBOption

func DBWithDialect added in v0.1.25

func DBWithDialect(dialect Dialect) DBOption

func DBWithMdls added in v0.1.27

func DBWithMdls(mdls ...Middleware) DBOption

func DBWithRegister

func DBWithRegister(r *schema.Register) DBOption

type Deleter

type Deleter[T any] struct {
	// contains filtered or unexported fields
}

func NewDeleter

func NewDeleter[T any](db *DB) *Deleter[T]

func (*Deleter[T]) Build

func (d *Deleter[T]) Build() (*Query, error)

func (*Deleter[T]) Exec

func (d *Deleter[T]) Exec(ctx context.Context) (sql.Result, error)

func (*Deleter[T]) From

func (d *Deleter[T]) From(tableName string) *Deleter[T]

func (*Deleter) Quoter added in v0.1.25

func (b *Deleter) Quoter(columnName string)

func (*Deleter[T]) Where

func (d *Deleter[T]) Where(e Predicate) *Deleter[T]

type Dialect added in v0.1.25

type Dialect interface {
	// 表名,列名标记符号 mysql `
	Quoter() string

	BuildOnDuplicateKey(b *builder, odk *OnDuplicateKey) error
}

type Executor

type Executor interface {
	Exec(ctx context.Context) Result
}

type Expression

type Expression interface {
	// contains filtered or unexported methods
}

type Handler added in v0.1.27

type Handler func(ctx context.Context, qc *QueryContext) *QueryResult

type Inserter added in v0.1.25

type Inserter[T any] struct {
	// contains filtered or unexported fields
}

func NewInserter added in v0.1.25

func NewInserter[T any](sess session) *Inserter[T]

func (*Inserter[T]) Build added in v0.1.25

func (i *Inserter[T]) Build() (*Query, error)

func (*Inserter[T]) Columns added in v0.1.25

func (i *Inserter[T]) Columns(columns ...string) *Inserter[T]

Columns 指定要插入的列

func (*Inserter[T]) Exec added in v0.1.25

func (i *Inserter[T]) Exec(ctx context.Context) Result

func (*Inserter[T]) OnDuplicateKey added in v0.1.25

func (i *Inserter[T]) OnDuplicateKey() *OnDuplicateKeyBuilder[T]

OnDuplicateKey 主键冲突时的操作

func (*Inserter) Quoter added in v0.1.25

func (b *Inserter) Quoter(columnName string)

func (*Inserter[T]) Values added in v0.1.25

func (i *Inserter[T]) Values(values ...*T) *Inserter[T]

type Join added in v0.1.36

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

join

func (Join) Join added in v0.1.36

func (j Join) Join(target TableReference) *JoinBuilder

func (Join) LeftJoin added in v0.1.36

func (j Join) LeftJoin(target TableReference) *JoinBuilder

func (Join) RightJoin added in v0.1.36

func (j Join) RightJoin(target TableReference) *JoinBuilder

type JoinBuilder added in v0.1.36

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

func (*JoinBuilder) On added in v0.1.36

func (j *JoinBuilder) On(ps ...Predicate) Join

type Middleware added in v0.1.27

type Middleware func(next Handler) Handler

type OnDuplicateKey added in v0.1.25

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

type OnDuplicateKeyBuilder added in v0.1.25

type OnDuplicateKeyBuilder[T any] struct {
	// contains filtered or unexported fields
}

func (*OnDuplicateKeyBuilder[T]) Update added in v0.1.25

func (b *OnDuplicateKeyBuilder[T]) Update(assigns ...Assignable) *Inserter[T]

type Predicate

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

func Not

func Not(right Predicate) Predicate

func (Predicate) And

func (left Predicate) And(right Predicate) Predicate

func (Predicate) Or

func (left Predicate) Or(right Predicate) Predicate

type Querier

type Querier[T any] interface {
	Get(ctx context.Context) (*T, error)
	GetMulti(ctx context.Context) ([]*T, error)
}

Querier querier 用于select语句

type Query

type Query struct {
	SQL  string
	Args []any
}

type QueryBuilder

type QueryBuilder interface {
	Build() (*Query, error)
}

type QueryContext added in v0.1.27

type QueryContext struct {
	Type QueryType

	Builder QueryBuilder
	// contains filtered or unexported fields
}

type QueryResult added in v0.1.27

type QueryResult struct {
	Result any

	Err error
}

type QueryType added in v0.1.27

type QueryType int
const (
	Select QueryType = iota
	Insert
	Delete
	Update
	RAW
)

type RawExpression added in v0.1.25

type RawExpression struct {
	Expr string
	Args []any
}

RawExpression raw expression will not do anything to this

func Raw added in v0.1.25

func Raw(expr string, args ...any) RawExpression

func (RawExpression) AsPredicate added in v0.1.25

func (r RawExpression) AsPredicate() Predicate

func (RawExpression) Select added in v0.1.25

func (r RawExpression) Select()

type RawQuerier added in v0.1.36

type RawQuerier[T any] struct {
	// contains filtered or unexported fields
}

func RawQuery added in v0.1.36

func RawQuery[T any](sess session, sql string, args ...any) *RawQuerier[T]

func (*RawQuerier[T]) Build added in v0.1.36

func (r *RawQuerier[T]) Build() (*Query, error)

func (*RawQuerier[T]) Exec added in v0.1.36

func (r *RawQuerier[T]) Exec(ctx context.Context) Result

func (*RawQuerier[T]) Get added in v0.1.36

func (r *RawQuerier[T]) Get(ctx context.Context) (*T, error)

func (*RawQuerier[T]) GetMulti added in v0.1.36

func (r *RawQuerier[T]) GetMulti(ctx context.Context) ([]*T, error)

type Result added in v0.1.25

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

func (Result) Err added in v0.1.25

func (r Result) Err() error

func (Result) LastInsertId added in v0.1.25

func (r Result) LastInsertId() (int64, error)

func (Result) RowsAffected added in v0.1.25

func (r Result) RowsAffected() (int64, error)

type Selectable added in v0.1.25

type Selectable interface {
	Select()
}

type Selector

type Selector[T any] struct {
	// contains filtered or unexported fields
}

func NewSelector

func NewSelector[T any](sess session) *Selector[T]

func (*Selector[T]) Build

func (s *Selector[T]) Build() (*Query, error)

func (*Selector[T]) From

func (s *Selector[T]) From(table TableReference) *Selector[T]

func (*Selector[T]) Get

func (s *Selector[T]) Get(ctx context.Context) (*T, error)

func (*Selector[T]) GetMulti

func (s *Selector[T]) GetMulti(ctx context.Context) ([]*T, error)

func (*Selector[T]) GroupBy added in v0.1.25

func (s *Selector[T]) GroupBy(groupBy ...Expression) *Selector[T]

func (*Selector[T]) Having added in v0.1.26

func (s *Selector[T]) Having(having ...Predicate) *Selector[T]

func (*Selector[T]) Limit added in v0.1.26

func (s *Selector[T]) Limit(limit int) *Selector[T]

func (*Selector[T]) OffSet added in v0.1.26

func (s *Selector[T]) OffSet(offSet int) *Selector[T]

func (*Selector) Quoter added in v0.1.25

func (b *Selector) Quoter(columnName string)

func (*Selector[T]) Select added in v0.1.25

func (s *Selector[T]) Select(cols ...Selectable) *Selector[T]

func (*Selector[T]) Where

func (s *Selector[T]) Where(e Predicate) *Selector[T]

type StandSQL added in v0.1.25

type StandSQL struct{}

func (StandSQL) BuildOnDuplicateKey added in v0.1.25

func (s StandSQL) BuildOnDuplicateKey(b *builder, odk *OnDuplicateKey) error

func (StandSQL) Quoter added in v0.1.25

func (s StandSQL) Quoter() string

type Table added in v0.1.36

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

普通表

func TableOf added in v0.1.36

func TableOf(entity any) Table

/=====================================

func (Table) As added in v0.1.36

func (t Table) As(alias string) Table

func (Table) C added in v0.1.36

func (t Table) C(name string) Column

func (Table) Join added in v0.1.36

func (t Table) Join(target TableReference) *JoinBuilder

func (Table) LeftJoin added in v0.1.36

func (t Table) LeftJoin(target TableReference) *JoinBuilder

func (Table) RightJoin added in v0.1.36

func (t Table) RightJoin(target TableReference) *JoinBuilder

type TableReference added in v0.1.36

type TableReference interface {
	// contains filtered or unexported methods
}

type Tx added in v0.1.26

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

func (*Tx) Commit added in v0.1.26

func (tx *Tx) Commit() error

func (*Tx) RollBack added in v0.1.26

func (tx *Tx) RollBack() error

Directories

Path Synopsis
internal
test
Package test 是用于辅助测试的包。
Package test 是用于辅助测试的包。
middleware
proto
gen
元数据注册中心
元数据注册中心
until

Jump to

Keyboard shortcuts

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