Documentation
¶
Overview ¶
Package sqldb helps create tables from Go structures.
Field tag format: `sqldb:"key[:value] key[:value]..."`. Available keys:
table: table name
col: column name, col:- to skip.
type: char, text and Go builtin types: string/bool/int/uint/int8...
precision: for string and char type, it's the 'length', such as precision:100,
for float and double it's 'precision, exact', such as precision: 32,5.
dbtype: the final database type, it will override type and precision key
pk: primary key
autoincr: auto increament
notnull: not null
default: default value, '-' to disable default
unique: unique constraint name or empty
fk: foreign key: TABLE.COLUMN
Index ¶
- func ErrAllowNoRows(err error) error
- func ErrOnNoAffects(n int64, err, newErr error) error
- func ErrOnNoAffectsResult(res sql.Result, err, newErr error) error
- func ErrOnNoRows(err, newErr error) error
- func Open(dialect DBDialect, config DBConfig) (*sql.DB, error)
- func ResultLastInsertId(result sql.Result, err error) (int64, error)
- func ResultRowsAffected(result sql.Result, err error) (int64, error)
- func SnakeCase(s string) string
- func TxDone(tx Tx, err *error) error
- func TxDoneClose(tx TxCloser, err *error) error
- type CheckIsExistGroup
- type Column
- type ColumnNameJoinRule
- type ColumnNames
- func (c ColumnNames) Cond(cond, check string) string
- func (c ColumnNames) Contains(col string) bool
- func (c ColumnNames) Copy() ColumnNames
- func (c ColumnNames) InplaceRemove(cols ...string) ColumnNames
- func (c ColumnNames) Join(rule ColumnNameJoinRule) string
- func (c ColumnNames) List() string
- func (c ColumnNames) NamedCond(cond, check string) string
- func (c ColumnNames) NamedList() string
- func (c ColumnNames) NamedUpdate() string
- func (c ColumnNames) Placeholders() string
- func (c ColumnNames) Update() string
- type DBConfig
- type DBDialect
- type MySQL
- type NameMapper
- type Postgres
- type SQLBuilder
- func (b *SQLBuilder) Delete(model interface{}, where string) string
- func (b *SQLBuilder) Insert(model interface{}) string
- func (b *SQLBuilder) InsertUnique(model interface{}, checkExist string) string
- func (b *SQLBuilder) IsExist(model interface{}, resultName string, where string) string
- func (b *SQLBuilder) MultiIsExist(groups ...CheckIsExistGroup) string
- func (b *SQLBuilder) Query(model interface{}, columns []string, where string) string
- func (b *SQLBuilder) Update(model interface{}, columns []string, where string) string
- func (b *SQLBuilder) WhereColumns(cols ...string) string
- func (b *SQLBuilder) WithCache(f func(b *SQLBuilder) string) string
- func (b *SQLBuilder) WithCacheAndIndex(f func(b *SQLBuilder, index int) string, index, cap int) string
- type SQLUtil
- func (s *SQLUtil) CreateTableSQL(table Table) (string, error)
- func (s *SQLUtil) CreateTables(db *sql.DB, models ...interface{}) error
- func (s *SQLUtil) DBDialect() DBDialect
- func (s *SQLUtil) EscapeName(name string) string
- func (s *SQLUtil) TableColumns(v interface{}, excepts ...string) ColumnNames
- func (s *SQLUtil) TableName(v interface{}) string
- func (s *SQLUtil) TableParser() *TableParser
- type SQLite3
- type Table
- type TableParser
- type TableParserOptions
- type Tx
- type TxCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrAllowNoRows ¶
func ErrOnNoAffects ¶
func ErrOnNoRows ¶
func TxDoneClose ¶
Types ¶
type CheckIsExistGroup ¶ added in v0.0.6
type ColumnNameJoinRule ¶
type ColumnNames ¶
type ColumnNames []string
func (ColumnNames) Cond ¶
func (c ColumnNames) Cond(cond, check string) string
func (ColumnNames) Contains ¶
func (c ColumnNames) Contains(col string) bool
func (ColumnNames) Copy ¶
func (c ColumnNames) Copy() ColumnNames
func (ColumnNames) InplaceRemove ¶
func (c ColumnNames) InplaceRemove(cols ...string) ColumnNames
func (ColumnNames) Join ¶
func (c ColumnNames) Join(rule ColumnNameJoinRule) string
func (ColumnNames) List ¶
func (c ColumnNames) List() string
func (ColumnNames) NamedCond ¶
func (c ColumnNames) NamedCond(cond, check string) string
func (ColumnNames) NamedList ¶
func (c ColumnNames) NamedList() string
func (ColumnNames) NamedUpdate ¶
func (c ColumnNames) NamedUpdate() string
func (ColumnNames) Placeholders ¶ added in v0.0.4
func (c ColumnNames) Placeholders() string
func (ColumnNames) Update ¶
func (c ColumnNames) Update() string
type DBConfig ¶
type DBConfig struct {
Type string `json:"type" yaml:"type" toml:"type"`
Host string `json:"host" yaml:"host" toml:"host"`
Port int `json:"port" yaml:"port" toml:"port"`
DBName string `json:"dbname" yaml:"dbname" toml:"dbname"`
User string `json:"user" yaml:"user" toml:"user"`
Password string `json:"password" yaml:"password" toml:"password"`
MaxIdle int `json:"maxIdle" yaml:"maxIdle" toml:"maxIdle"`
MaxOpen int `json:"maxOpen" yaml:"maxOpen" toml:"maxOpen"`
MaxLifetime int `json:"maxLifetime" yaml:"maxLifetime" toml:"maxLifetime"`
Options map[string]string `json:"options" yaml:"options" toml:"options"`
}
func (*DBConfig) ApplyDefault ¶
func (*DBConfig) JoinOptions ¶
type NameMapper ¶
type SQLBuilder ¶ added in v0.0.6
type SQLBuilder struct {
SQLUtil *SQLUtil
// contains filtered or unexported fields
}
func NewSQLBuilder ¶ added in v0.0.6
func NewSQLBuilder(su *SQLUtil) *SQLBuilder
func (*SQLBuilder) Delete ¶ added in v0.0.6
func (b *SQLBuilder) Delete(model interface{}, where string) string
func (*SQLBuilder) Insert ¶ added in v0.0.6
func (b *SQLBuilder) Insert(model interface{}) string
func (*SQLBuilder) InsertUnique ¶ added in v0.0.6
func (b *SQLBuilder) InsertUnique(model interface{}, checkExist string) string
func (*SQLBuilder) IsExist ¶ added in v0.0.6
func (b *SQLBuilder) IsExist(model interface{}, resultName string, where string) string
func (*SQLBuilder) MultiIsExist ¶ added in v0.0.6
func (b *SQLBuilder) MultiIsExist(groups ...CheckIsExistGroup) string
func (*SQLBuilder) Query ¶ added in v0.0.6
func (b *SQLBuilder) Query(model interface{}, columns []string, where string) string
func (*SQLBuilder) Update ¶ added in v0.0.6
func (b *SQLBuilder) Update(model interface{}, columns []string, where string) string
func (*SQLBuilder) WhereColumns ¶ added in v0.0.8
func (b *SQLBuilder) WhereColumns(cols ...string) string
func (*SQLBuilder) WithCache ¶ added in v0.0.7
func (b *SQLBuilder) WithCache(f func(b *SQLBuilder) string) string
func (*SQLBuilder) WithCacheAndIndex ¶ added in v0.0.7
func (b *SQLBuilder) WithCacheAndIndex(f func(b *SQLBuilder, index int) string, index, cap int) string
type SQLUtil ¶
type SQLUtil struct {
// contains filtered or unexported fields
}
func NewSQLUtil ¶
func NewSQLUtil(parser *TableParser, dialect DBDialect) *SQLUtil
func (*SQLUtil) CreateTables ¶
func (*SQLUtil) EscapeName ¶ added in v0.0.3
func (*SQLUtil) TableColumns ¶
func (s *SQLUtil) TableColumns(v interface{}, excepts ...string) ColumnNames
func (*SQLUtil) TableParser ¶
func (s *SQLUtil) TableParser() *TableParser
type TableParser ¶
type TableParser struct {
// contains filtered or unexported fields
}
func NewTableParser ¶
func NewTableParser(options ...TableParserOptions) *TableParser
func (*TableParser) StructTable ¶
func (p *TableParser) StructTable(v interface{}) (Table, error)
type TableParserOptions ¶
Click to show internal directories.
Click to hide internal directories.