gsd

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 20 Imported by: 0

README

gsd

gsd is a lightweight, fluent SQL data access library. It supports various types of database, like mysql/mssql/sqlite etc.

  • High performance
  • Support context.Context
  • Support opentracing

Configure

gsd use auxo/config package to manage database options. There is a sample config file in the package(app.yml):

db.sql:
    test:
      provider: mysql
      address: localhost:27017/test
      trace:
        enabled: true
        time: 1s
      options:
        max_open_conns: 100
        max_idle_conns: 1

Once you add configuration to app.yml, you can open a database like this:

db, err := gsd.Open("Test")
......

Usage

The API of gsd is very similar to native SQL expression.

Let's define a dummy User struct first.

type User struct {
	ID         int32         `gsd:"id,pk,auto"`
	Name       string        `gsd:"name"`
	Sex        bool          `gsd:"sex"`
	Age        gsd.NullInt32 `gsd:"age"`
	Salary     float32       `gsd:"salary"`
	CreateTime string        `gsd:"create_time,insert:false"`
}
INSERT
r, err := db.Insert("user").Columns("id", "name").Values(1, "abc").Values(2, "xyz").Result()
// ...

OR

user := &User{
	ID:   100,
	Name: "abc",
}
err := db.Create(user)
// or specify columns
// err = db.Create(user, Include("id", "name"))
DELETE
r, err := db.Delete("user").Where(Equal("id", 1)).Result()
// ...

OR

user := &User{
	ID: 3,
}
r, err := db.Remove(user)
UPDATE
r, err := db.Update("user").
		Set("name", "xyz").
		Inc("c1", 1).
		Dec("c2", 1).
		Expr("c3", "c4+10").
		Where(Equal("id", 1)).
		Result()

OR

r, err := db.Modify(user)
// or specify columns
r, err = db.Modify(user, Omit("code"))
SELECT
err := db.Select("id", "name", "salary", "age", "sex", "create_time").
	From("user").
	Where(Equal("id", 2)).
	Fill(user)

A more complex example

err = db.Query(C("id", "name", "salary", "age", "sex", "create_time"), true).
	From("user").
	Join("userinfo", On("id", "auto_id")).
	Where(Equal("id", -1)).
	GroupBy(C("age")).
	Having(Equal("age", 10)).
	OrderBy(C("id").ASC()).
	Limit(10, 10).
	Fill(user)

OR

user := &User{
	ID: 3,
}
err := db.Load(user)
COUNT
err := db.Count("user").Scan(&count)
// or
count, err = db.Count("user").Value()
TRANSACTION
err := db.Transact(func(tx gsd.TX) error {
	count, err := tx.Count("user").Value()
	t.Log(count, err)
	return err
})
if err != nil {
	log.Fatal(err)
}

TODO

  • More proxy actions.

Documentation

Index

Constants

View Source
const (
	EQ = iota
	NE
	LT
	LTE
	GT
	GTE
	IN
	NIN
	LK
)
View Source
const PkgName = "auxo.db.gsd"

Variables

View Source
var (
	DefaultTableOptions = &TableOptions{
		NameStyle:       texts.Lower,
		ColumnNameStyle: texts.Lower,
	}
)
View Source
var (
	ErrNoRows = sql.ErrNoRows
)
View Source
var ErrTXCancelled = errors.New("gsd: transaction has been cancelled")

Functions

func RegisterProvider

func RegisterProvider(name string, builder ProviderBuilder)

func RegisterType

func RegisterType(i interface{}, options *TableOptions)

func Use

func Use(fs ...Filter)

func UseDB

func UseDB(db string, fs ...Filter)

Types

type AndCriteriaSet

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

func (*AndCriteriaSet) Empty

func (c *AndCriteriaSet) Empty() bool

func (*AndCriteriaSet) Joiner

func (c *AndCriteriaSet) Joiner() string

func (*AndCriteriaSet) Left

func (c *AndCriteriaSet) Left() CriteriaSet

func (*AndCriteriaSet) Right

func (c *AndCriteriaSet) Right() CriteriaSet

type Builder

type Builder struct {
	texts.Builder
	Args []interface{}
}

func (*Builder) Reset

func (b *Builder) Reset()

type CallInfo

type CallInfo struct {
	SP   string
	Args []interface{}
}

type Column

type Column interface {
	Table() Table
	Name() string
	Alias() string
	Field() string
}

func NewColumn

func NewColumn(name string, alias ...string) Column

func NewExprColumn

func NewExprColumn(expr, alias string) Column

func NewTableColumn

func NewTableColumn(table interface{}, name string, alias ...string) Column

type ColumnFilter

type ColumnFilter func(cols []string) []string

func Include

func Include(cols ...string) ColumnFilter

func Omit

func Omit(cols ...string) ColumnFilter

type ColumnOptions

type ColumnOptions struct {
	Name          string `json:"name"`
	AutoIncrement bool   `json:"auto"`
	PrimaryKey    bool   `json:"pk"`
	ForeignKey    bool   `json:"fk"`
	Insert        bool   `json:"insert"`
	Update        bool   `json:"update"`
	Select        bool   `json:"select"`
	Where         *struct {
		Column string
		Type   int
		Index  int
	}
	Size int `json:"size"`
}

ColumnOptions is table column options

type Columns

type Columns []Column

func NewColumns

func NewColumns(cols ...string) *Columns

func (*Columns) ASC

func (c *Columns) ASC() *Order

func (*Columns) Alias

func (c *Columns) Alias(t Table, col, alias string) *Columns

func (*Columns) DESC

func (c *Columns) DESC() *Order

func (*Columns) Expr

func (c *Columns) Expr(expr, alias string) *Columns

func (*Columns) Simple

func (c *Columns) Simple(cols ...string) *Columns

func (*Columns) Table

func (c *Columns) Table(t interface{}, cols ...string) *Columns

type CountClause

type CountClause interface {
	Join(table interface{}, on CriteriaSet) CountClause
	LeftJoin(t interface{}, on CriteriaSet) CountClause
	RightJoin(t interface{}, on CriteriaSet) CountClause
	FullJoin(t interface{}, on CriteriaSet) CountClause
	Where(f CriteriaSet) CountWhereClause
	CountResultClause
}

type CountGroupByClause

type CountGroupByClause interface {
	Having(f CriteriaSet) CountResultClause
	CountResultClause
}

type CountResultClause

type CountResultClause interface {
	Value() (int, error)
	Scan(dst interface{}) error
}

type CountWhereClause

type CountWhereClause interface {
	GroupBy(cols *Columns) CountGroupByClause
	CountResultClause
}

type Criteria

type Criteria interface {
}

type CriteriaSet

type CriteriaSet interface {
	Empty() bool
}

func And

func And(left, right CriteriaSet) CriteriaSet

func Not

func Not(inner CriteriaSet) CriteriaSet

func Or

func Or(left, right CriteriaSet) CriteriaSet

type DB

type DB interface {
	Insert(ctx context.Context, table string) InsertClause
	Create(ctx context.Context, i interface{}, filter ...ColumnFilter) error
	Delete(ctx context.Context, table string) DeleteClause
	Remove(ctx context.Context, i interface{}) (r Result, err error)
	Update(ctx context.Context, table string) UpdateClause
	Modify(ctx context.Context, i interface{}, filter ...ColumnFilter) (r Result, err error)
	Select(ctx context.Context, cols ...string) SelectClause
	//Distinct(ctx context.Context, cols ...string) SelectClause
	Query(ctx context.Context, cols *Columns, distinct ...bool) SelectClause
	Load(ctx context.Context, i interface{}) error
	Count(ctx context.Context, table interface{}) CountClause
	Execute(ctx context.Context, sql string, args ...interface{}) ExecuteClause
	//Call(ctx context.Context, sp string, args ...interface{}) CallClause
	Prepare(ctx context.Context, query string) (*Stmt, error)
	Stmt(name string, b func() string) (*Stmt, error)
	Transact(ctx context.Context, fn func(tx TX) error, opts ...*sql.TxOptions) (err error)
}

func MustOpen

func MustOpen(name string) (db DB)

func New

func New(opts *Options) (DB, error)

func Open

func Open(name string) (db DB, err error)

type DecValue

type DecValue struct {
	Value any
}

type DeleteClause

type DeleteClause interface {
	Where(f CriteriaSet) ResultClause
}

type DeleteInfo

type DeleteInfo struct {
	Table string
	Where CriteriaSet
}

type ExecuteClause

type ExecuteClause interface {
	Result() (ExecuteResult, error)
	Value() Value
	Scan(dst ...interface{}) error
	Fill(i interface{}) error
	//One(i interface{}) error
	//All(i interface{}) error
	Reader() (Reader, error)
	For(fn func(r Reader) error) error
}

type ExecuteInfo

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

type ExecuteResult

type ExecuteResult interface {
	Result
	LastInsertId() (int64, error)
}

type Executor

type Executor interface {
	Database() string
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
	QueryRows(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

type ExprColumn

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

func (*ExprColumn) Alias

func (c *ExprColumn) Alias() string

func (*ExprColumn) Field

func (c *ExprColumn) Field() string

func (*ExprColumn) Name

func (c *ExprColumn) Name() string

func (*ExprColumn) Table

func (c *ExprColumn) Table() Table

type ExprCriteria

type ExprCriteria string

type ExprValue

type ExprValue struct {
	Value string
}

type Factory

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

func (*Factory) Open

func (f *Factory) Open(name string) (db DB, err error)

type Filter

type Filter func(Executor) Executor

type Filters

type Filters []Filter

func (Filters) Apply

func (fs Filters) Apply(e Executor) Executor

type FromClause

type FromClause interface {
	LimitClause
	SelectResultClause
	Join(table interface{}, on CriteriaSet) JoinClause
	LeftJoin(t interface{}, on CriteriaSet) JoinClause
	RightJoin(t interface{}, on CriteriaSet) JoinClause
	FullJoin(t interface{}, on CriteriaSet) JoinClause
	Where(f CriteriaSet) WhereClause
}

type GroupByClause

type GroupByClause interface {
	LimitClause
	OrderBy(orders ...*Order) OrderByClause
	Having(f CriteriaSet) HavingClause
	SelectResultClause
}

type HavingClause

type HavingClause interface {
	LimitClause
	SelectResultClause
	OrderBy(orders ...*Order) OrderByClause
}

type IncValue

type IncValue struct {
	Value any
}

type InsertClause

type InsertClause interface {
	Columns(cols ...string) InsertColumnsClause
}

type InsertColumnsClause

type InsertColumnsClause interface {
	Values(values ...interface{}) InsertValuesClause
}

type InsertInfo

type InsertInfo struct {
	Table   string
	Columns []string
	Values  []interface{} // single row or multiple rows
	Filter  ColumnFilter
}

type InsertResult

type InsertResult interface {
	Result
	LastInsertId() (int64, error)
}

type InsertResultClause

type InsertResultClause interface {
	Submit() error
	Result() (InsertResult, error)
}

type InsertValuesClause

type InsertValuesClause interface {
	Values(values ...interface{}) InsertValuesClause
	InsertResultClause
}

type JoinClause

type JoinClause interface {
	FromClause
}

type JoinCriteriaSet

type JoinCriteriaSet interface {
	CriteriaSet
	Left() CriteriaSet
	Right() CriteriaSet
	Joiner() string
}

type LazyDB

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

func Lazy

func Lazy(name string) *LazyDB

func (*LazyDB) Get

func (l *LazyDB) Get() (db DB)

func (*LazyDB) Try

func (l *LazyDB) Try() (db DB, err error)

type LimitClause

type LimitClause interface {
	//Lock(Exclusive/Shared) SelectResultClause
	Limit(skip, take int) SelectResultClause
	Page(index, size int) SelectResultClause
}

type Meta

type Meta struct {
	ID          int32
	Table       string
	Auto        string   // auto increment column
	PrimaryKeys []string // primary key columns
	//ForeignKeys   []string // foreign key columns
	Updates []string // update columns
	Inserts []string // insert columns
	Selects []string // select columns
	Columns []string // all columns, columns = keys + updates = autos + inserts
	Wheres  []*struct {
		Column string
		Type   int
		Index  int
	}
	// contains filtered or unexported fields
}

func GetMeta

func GetMeta(t reflect.Type) *Meta

func (*Meta) CopyInsertValues

func (m *Meta) CopyInsertValues(i interface{}, values []interface{})

CopyInsertValues copy values of insert-fields to struct i

func (*Meta) CopyPrimaryKeyValues

func (m *Meta) CopyPrimaryKeyValues(i interface{}, values []interface{})

CopyPrimaryKeyValues copy values of pk-fields to struct i

func (*Meta) CopyUpdateValues

func (m *Meta) CopyUpdateValues(i interface{}, values []interface{})

CopyUpdateValues copy values of update-fields to struct i

func (*Meta) CopyValues

func (m *Meta) CopyValues(i interface{}, values []interface{}, cols ...string)

CopyValues copy fields to struct i

func (*Meta) InsertValues

func (m *Meta) InsertValues(i interface{}) []interface{}

InsertValues return values of insert-fields

func (*Meta) Pointers

func (m *Meta) Pointers(i interface{}, cols ...string) []interface{}

Pointers return pointers of fields for scanning

func (*Meta) PrimaryKeyValues

func (m *Meta) PrimaryKeyValues(i interface{}) []interface{}

PrimaryKeyValues return values of key-fields

func (*Meta) SetAutoValue

func (m *Meta) SetAutoValue(i interface{}, value int64)

SetAutoValue set value of auto increment field

func (*Meta) SetValue

func (m *Meta) SetValue(i interface{}, col string, val interface{})

func (*Meta) UpdateValues

func (m *Meta) UpdateValues(i interface{}) []interface{}

UpdateValues return values of update-fields

func (*Meta) Value

func (m *Meta) Value(i interface{}, col string) interface{}

func (*Meta) Values

func (m *Meta) Values(i interface{}, cols ...string) []interface{}

Values return fields values

func (*Meta) WhereValues

func (m *Meta) WhereValues(i interface{}) CriteriaSet

WhereValues return values of searching criteria set.

type MetaFactory

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

func (*MetaFactory) GetMeta

func (f *MetaFactory) GetMeta(t reflect.Type) *Meta

func (*MetaFactory) SetMeta

func (f *MetaFactory) SetMeta(t reflect.Type, m *Meta)

type NotCriteriaSet

type NotCriteriaSet struct {
	Inner CriteriaSet
}

func (*NotCriteriaSet) Empty

func (c *NotCriteriaSet) Empty() bool

type NullFloat32

type NullFloat32 struct {
	Float32 float32
	Valid   bool // Valid is true if Float32 is not NULL
}

func (*NullFloat32) Scan

func (n *NullFloat32) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (NullFloat32) Value

func (n NullFloat32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt32

type NullInt32 struct {
	Int32 int32
	Valid bool // Valid is true if Int32 is not NULL
}

func (*NullInt32) Scan

func (n *NullInt32) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (NullInt32) Value

func (n NullInt32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if NullTime is not NULL
}

NullTime is a nullable NullTime value

func (*NullTime) Scan

func (n *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullTime) Value

func (n NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type OneColumnCriteria

type OneColumnCriteria struct {
	Column
	Type  int
	Value interface{}
}

type Options

type Options struct {
	Name         string
	Provider     string
	Driver       string
	Address      string
	MaxOpenConns int
	MaxIdleConns int
	ConnLifetime time.Duration
	Trace        struct {
		Enabled bool
		Time    time.Duration
	}
	Options data.Map
}

type OrCriteriaSet

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

func (*OrCriteriaSet) Empty

func (c *OrCriteriaSet) Empty() bool

func (*OrCriteriaSet) Joiner

func (c *OrCriteriaSet) Joiner() string

func (*OrCriteriaSet) Left

func (c *OrCriteriaSet) Left() CriteriaSet

func (*OrCriteriaSet) Right

func (c *OrCriteriaSet) Right() CriteriaSet

type Order

type Order struct {
	Type OrderType
	Columns
}

type OrderByClause

type OrderByClause interface {
	LimitClause
	SelectResultClause
}

type OrderType

type OrderType int
const (
	ASC OrderType = iota
	DESC
)

type Provider

type Provider interface {
	BuildInsert(b *Builder, ctx *InsertInfo) (err error)
	BuildDelete(b *Builder, ctx *DeleteInfo) (err error)
	BuildUpdate(b *Builder, ctx *UpdateInfo) (err error)
	BuildSelect(b *Builder, ctx *SelectInfo) (err error)
	BuildCall(b *Builder, ctx *CallInfo) (err error)
}

type ProviderBuilder

type ProviderBuilder func(options data.Map) Provider

type Reader

type Reader interface {
	Scan(dst ...interface{}) error
	Fill(i interface{}) error
	Next() bool
	NextSet() bool
	Close() error
	Err() error
}

type Result

type Result interface {
	RowsAffected() (int64, error)
}

type ResultClause

type ResultClause interface {
	Result() (Result, error)
}

type SelectClause

type SelectClause interface {
	From(table interface{}) FromClause
}

type SelectInfo

type SelectInfo struct {
	Table
	Distinct bool
	Columns
	Where CriteriaSet
	Joins []struct {
		Type string
		Table
		On CriteriaSet
	}
	Groups Columns
	Having CriteriaSet
	Orders []*Order
	Skip   int
	Take   int
	Count  bool // return total count
}

type SelectResultClause

type SelectResultClause interface {
	Value() Value
	//Int() (int, error)
	Scan(dst ...interface{}) error
	Fill(i interface{}) error
	//One(i interface{}) error
	//All(i interface{}) error
	List(i interface{}, total *int) error
	Reader() (Reader, error)
	For(fn func(r Reader) error) error
}

type SetClause

type SetClause interface {
	UpdateClause
	ResultClause
	Where(f CriteriaSet) ResultClause
}

type SimpleColumn

type SimpleColumn string

func (SimpleColumn) Alias

func (c SimpleColumn) Alias() string

func (SimpleColumn) Field

func (c SimpleColumn) Field() string

func (SimpleColumn) Name

func (c SimpleColumn) Name() string

func (SimpleColumn) Table

func (SimpleColumn) Table() Table

type SimpleCriteriaSet

type SimpleCriteriaSet struct {
	Items []Criteria
}

func Equal

func Equal(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Between

func (c *SimpleCriteriaSet) Between(col, start, end interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Contains

func (c *SimpleCriteriaSet) Contains(col interface{}, s string) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Date

func (c *SimpleCriteriaSet) Date(col interface{}, date time.Time) *SimpleCriteriaSet

func (*SimpleCriteriaSet) DateRange

func (c *SimpleCriteriaSet) DateRange(col interface{}, start, end time.Time) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Empty

func (c *SimpleCriteriaSet) Empty() bool

func (*SimpleCriteriaSet) Equal

func (c *SimpleCriteriaSet) Equal(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Equal2

func (c *SimpleCriteriaSet) Equal2(left, right interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) EqualIf

func (c *SimpleCriteriaSet) EqualIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Greater

func (c *SimpleCriteriaSet) Greater(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Greater2

func (c *SimpleCriteriaSet) Greater2(left, right interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) GreaterIf

func (c *SimpleCriteriaSet) GreaterIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) GreaterOrEqual

func (c *SimpleCriteriaSet) GreaterOrEqual(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) GreaterOrEqual2

func (c *SimpleCriteriaSet) GreaterOrEqual2(left, right interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) GreaterOrEqualIf

func (c *SimpleCriteriaSet) GreaterOrEqualIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) In

func (c *SimpleCriteriaSet) In(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) InIf

func (c *SimpleCriteriaSet) InIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Less

func (c *SimpleCriteriaSet) Less(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Less2

func (c *SimpleCriteriaSet) Less2(left, right interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) LessIf

func (c *SimpleCriteriaSet) LessIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) LessOrEqual

func (c *SimpleCriteriaSet) LessOrEqual(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) LessOrEqual2

func (c *SimpleCriteriaSet) LessOrEqual2(left, right interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) LessOrEqualIf

func (c *SimpleCriteriaSet) LessOrEqualIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Like

func (c *SimpleCriteriaSet) Like(col interface{}, expr string) *SimpleCriteriaSet

Like add a LIKE criteria

c.Like("name", "%abc")
c.Like("name", "abc_")

func (*SimpleCriteriaSet) LikeIf

func (c *SimpleCriteriaSet) LikeIf(when bool, col interface{}, expr string) *SimpleCriteriaSet

func (*SimpleCriteriaSet) NotEqual

func (c *SimpleCriteriaSet) NotEqual(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) NotEqual2

func (c *SimpleCriteriaSet) NotEqual2(left, right interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) NotEqualIf

func (c *SimpleCriteriaSet) NotEqualIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) NotIn

func (c *SimpleCriteriaSet) NotIn(col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) NotInIf

func (c *SimpleCriteriaSet) NotInIf(when bool, col, val interface{}) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Prefix

func (c *SimpleCriteriaSet) Prefix(col interface{}, s string) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Suffix

func (c *SimpleCriteriaSet) Suffix(col interface{}, s string) *SimpleCriteriaSet

func (*SimpleCriteriaSet) Wild

Wild add a custom expression criteria

f.Wild("a > (b + 100)")

type Stmt

type Stmt sql.Stmt

func (*Stmt) Execute

func (s *Stmt) Execute(args ...interface{}) ExecuteClause

type TX

type TX interface {
	Insert(ctx context.Context, table string) InsertClause
	Create(ctx context.Context, i interface{}, filter ...ColumnFilter) error
	Delete(ctx context.Context, table string) DeleteClause
	Remove(ctx context.Context, i interface{}) (r Result, err error)
	Update(ctx context.Context, table string) UpdateClause
	Modify(ctx context.Context, i interface{}, filter ...ColumnFilter) (r Result, err error)
	Select(ctx context.Context, cols ...string) SelectClause
	Query(ctx context.Context, cols *Columns, distinct ...bool) SelectClause
	Load(ctx context.Context, i interface{}) error
	Count(ctx context.Context, table interface{}) CountClause
	Execute(ctx context.Context, sql string, args ...interface{}) ExecuteClause
	Prepare(ctx context.Context, query string) (*Stmt, error)
	Stmt(name string, b func() string) (*Stmt, error)
	Commit() error
	Rollback() error
}

type Table

type Table interface {
	Name() string
	Alias() string
	Prefix() string
}

func NewTable

func NewTable(name string, alias ...string) Table

type TableColumn

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

func (*TableColumn) Alias

func (c *TableColumn) Alias() string

func (*TableColumn) Field

func (c *TableColumn) Field() string

func (*TableColumn) Name

func (c *TableColumn) Name() string

func (*TableColumn) Table

func (c *TableColumn) Table() Table

type TableOptions

type TableOptions struct {
	Name            string
	NameStyle       texts.NameStyle
	ColumnNameStyle texts.NameStyle
}

type TwoColumnCriteria

type TwoColumnCriteria struct {
	Left  Column
	Right Column
	Type  int
}

type UpdateClause

type UpdateClause interface {
	Set(col string, val interface{}) SetClause
	Inc(col string, val interface{}) SetClause
	Dec(col string, val interface{}) SetClause
	Expr(col string, val string) SetClause
}

type UpdateInfo

type UpdateInfo struct {
	Table   string
	Columns []string
	Values  []interface{}
	Where   CriteriaSet
	Filter  ColumnFilter
}

type Value

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

func (Value) Int

func (v Value) Int() (i int, err error)

func (Value) Int32

func (v Value) Int32() (int32, error)

func (Value) Int64

func (v Value) Int64() (i int64, err error)

func (Value) String

func (v Value) String() (string, error)

type WhereClause

type WhereClause interface {
	LimitClause
	//One(i interface{}) error
	SelectResultClause
	GroupBy(cols *Columns) GroupByClause
	OrderBy(orders ...*Order) OrderByClause
}

Directories

Path Synopsis
filter

Jump to

Keyboard shortcuts

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