fmorm

package
v0.0.0-...-d20bc16 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](cb *CmdBuilder) (ret []*T)

func DeleteByModel

func DeleteByModel(d *Orm, model TableNameProvider) int64

func DeleteWhere

func DeleteWhere(d *Orm, model TableNameProvider, clause any, args ...any) int64

func InsertModelGetId

func InsertModelGetId(d *Orm, model TableNameProvider) int64

func One

func One[T any](cb *CmdBuilder) (ret T)

func OneByModel

func OneByModel[T TableNameProvider](d *Orm, model T) (_ T)

func OneWhere

func OneWhere[T TableNameProvider](d *Orm, clause any, args ...any) (ret T)

func UpdateModelByModel

func UpdateModelByModel(d *Orm, model TableNameProvider, where TableNameProvider) int64

func UpdateModelWhere

func UpdateModelWhere(d *Orm, model TableNameProvider, clause any, args ...any) int64

Types

type And

type And []CondMap

func (And) ToClause

func (c And) ToClause(orm *Orm, clause *strings.Builder, args *[]any) error

type ClauseProvider

type ClauseProvider interface {
	ToClause(orm *Orm, clause *strings.Builder, args *[]any) error
}

type CmdBuilder

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

func NewCmdBuilder

func NewCmdBuilder(orm *Orm) *CmdBuilder

func (*CmdBuilder) Columns

func (cb *CmdBuilder) Columns(cols ...string) *CmdBuilder

Columns is only for UPDATE/INSERT

func (*CmdBuilder) Delete

func (cb *CmdBuilder) Delete() (sql.Result, error)

func (*CmdBuilder) GroupBy

func (cb *CmdBuilder) GroupBy(groupBy string) *CmdBuilder

func (*CmdBuilder) Having

func (cb *CmdBuilder) Having(clause any, args ...any) *CmdBuilder

func (*CmdBuilder) InsertFull

func (cb *CmdBuilder) InsertFull(row any) (sql.Result, error)

func (*CmdBuilder) InsertModel

func (cb *CmdBuilder) InsertModel(row any) (sql.Result, error)

func (*CmdBuilder) InsertRow

func (cb *CmdBuilder) InsertRow(row any) (sql.Result, error)

func (*CmdBuilder) Limit

func (cb *CmdBuilder) Limit(n ...int) *CmdBuilder

Limit demo SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15

func (*CmdBuilder) OrderBy

func (cb *CmdBuilder) OrderBy(orderBy string) *CmdBuilder

func (*CmdBuilder) SelectAll

func (cb *CmdBuilder) SelectAll(rowsPtr any) error

func (*CmdBuilder) SelectOne

func (cb *CmdBuilder) SelectOne(result any) (found bool, err error)

func (*CmdBuilder) Table

func (cb *CmdBuilder) Table(v any) *CmdBuilder

func (*CmdBuilder) UpdateFull

func (cb *CmdBuilder) UpdateFull(row any) (sql.Result, error)

func (*CmdBuilder) UpdateModel

func (cb *CmdBuilder) UpdateModel(row any) (sql.Result, error)

func (*CmdBuilder) UpdateRow

func (cb *CmdBuilder) UpdateRow(row any) (sql.Result, error)

func (*CmdBuilder) Where

func (cb *CmdBuilder) Where(clause any, args ...any) *CmdBuilder

func (*CmdBuilder) WhereModel

func (cb *CmdBuilder) WhereModel(model TableNameProvider) *CmdBuilder

type CondMap

type CondMap map[string]any // NOTE: Go map has no order ....

func Cond

func Cond(sub any) CondMap

func CondArgs

func CondArgs(sql string, args ...any) CondMap

func CondModel

func CondModel(sub any) CondMap

func (CondMap) ToClause

func (condMap CondMap) ToClause(orm *Orm, clause *strings.Builder, args *[]any) error

ToClause NOTE: go map has no order ....

type DbExecutor

type DbExecutor interface {
	Exec(query string, args ...any) (sql.Result, error)
	Select(dest any, query string, args ...any) error
	Get(dest any, query string, args ...any) error
}

type Dialect

type Dialect interface {
	QuoteName(string) string
	NameQuoter() (string, string)
}

type DialectMySQL

type DialectMySQL struct {
}

func (*DialectMySQL) NameQuoter

func (d *DialectMySQL) NameQuoter() (string, string)

func (*DialectMySQL) QuoteName

func (d *DialectMySQL) QuoteName(s string) string

type DialectNop

type DialectNop struct {
}

func (*DialectNop) NameQuoter

func (d *DialectNop) NameQuoter() (string, string)

func (*DialectNop) QuoteName

func (d *DialectNop) QuoteName(s string) string

type ModelStructField

type ModelStructField struct {
	Name  string
	Value any
}

type ModelStructFields

type ModelStructFields []*ModelStructField

type NotAnd

type NotAnd []CondMap

func (NotAnd) ToClause

func (c NotAnd) ToClause(orm *Orm, clause *strings.Builder, args *[]any) error

type NotOr

type NotOr []CondMap

func (NotOr) ToClause

func (c NotOr) ToClause(orm *Orm, clause *strings.Builder, args *[]any) error

type Or

type Or []CondMap

func (Or) ToClause

func (c Or) ToClause(orm *Orm, clause *strings.Builder, args *[]any) error

type Orm

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

func NewOrm

func NewOrm(DB *sqlx.DB) *Orm

func (*Orm) Cmd

func (d *Orm) Cmd() *CmdBuilder

func (*Orm) Columns

func (d *Orm) Columns(cols ...string) *CmdBuilder

func (*Orm) Exec

func (d *Orm) Exec(query string, args ...any) (sql.Result, error)

func (*Orm) Get

func (d *Orm) Get(dest any, query string, args ...any) error

func (*Orm) Select

func (d *Orm) Select(dest any, query string, args ...any) error

func (*Orm) Table

func (d *Orm) Table(t any) *CmdBuilder

func (*Orm) Where

func (d *Orm) Where(clause any, args ...any) *CmdBuilder

func (*Orm) WhereModel

func (d *Orm) WhereModel(model TableNameProvider) *CmdBuilder

type SqlCmd

type SqlCmd struct {
	Query strings.Builder
	Args  []any
}

func (*SqlCmd) Append

func (sc *SqlCmd) Append(strs ...string) *SqlCmd

func (*SqlCmd) AppendClause

func (sc *SqlCmd) AppendClause(orm *Orm, c ClauseProvider) error

func (*SqlCmd) AppendStrings

func (sc *SqlCmd) AppendStrings(strs []string, optSep ...string) *SqlCmd

type TableNameProvider

type TableNameProvider interface {
	TableName() string
}

Jump to

Keyboard shortcuts

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