Documentation ¶
Index ¶
- Constants
- Variables
- func AddSqlArgs(sql string, args []interface{}, intoSql *string, intoArgs *[]interface{})
- func GenDeleteSql(table string, selector queries.Selector) (string, []interface{}, error)
- func GenGetSql(table string, cols []string, selector queries.Selector) (string, []interface{}, error)
- func GenInsertSql(table string, sample interface{}, db Driver) (string, []interface{}, error)
- func GenListSql(table string, cols []string, selector queries.Selector, orderby []string, ...) (string, string, []interface{}, error)
- func GenUpdateSql(table string, sample interface{}, db Driver) (string, []interface{}, error)
- func Ints2sql(array []int64) string
- func IsNil(rv reflect.Value) bool
- func NewCurTime(t TimeType, cur time.Time) interface{}
- func Register(name string, d DBFactory)
- func SetClock(clock clock.Clock)
- func Strings2sql(array []string) string
- func WithInterface(ctx context.Context, orm Interface) context.Context
- type DB
- type DBFactory
- type DBOption
- func WithConnMaxIdletime(d time.Duration) DBOption
- func WithConnMaxLifetime(d time.Duration) DBOption
- func WithContext(ctx context.Context) DBOption
- func WithDirver(driver string) DBOption
- func WithDsn(dsn string) DBOption
- func WithIgnoreNotFound() DBOption
- func WithMaxIdleCount(n int) DBOption
- func WithMaxOpenConns(n int) DBOption
- func WithMaxRows(n int) DBOption
- func WithoutPing() DBOption
- type DBOptions
- type DataType
- type Driver
- type Execer
- type Interface
- type Option
- func WithCols(cols ...string) Option
- func WithIgnoreNotFoundErr() Option
- func WithLimit(offset, limit int64) Option
- func WithOrderby(orderby ...string) Option
- func WithSample(sample interface{}) Option
- func WithSelector(selector string) Option
- func WithTable(table string) Option
- func WithTotal(total *int64) Option
- type Options
- func (o *Options) Error(err error) error
- func (p *Options) GenDeleteSql() (string, []interface{}, error)
- func (p *Options) GenGetSql() (string, []interface{}, error)
- func (p *Options) GenInsertSql(db Driver) (string, []interface{}, error)
- func (p *Options) GenListSql() (query, countQuery string, args []interface{}, err error)
- func (p *Options) GenUpdateSql(db Driver) (string, []interface{}, error)
- func (o *Options) Sample() interface{}
- func (p *Options) Table() string
- type RawDB
- type Rows
- type RowsIter
- type Set
- type Store
- type StructField
- type StructFields
- type TimeType
- type Tx
Constants ¶
View Source
const (
DefaultMaxRows = 1000
)
Variables ¶
View Source
var ( DefaultStringSize = 255 DEBUG = false )
Functions ¶
func AddSqlArgs ¶ added in v0.0.2
func GenDeleteSql ¶ added in v0.0.2
func GenInsertSql ¶
func GenListSql ¶ added in v0.0.2
func GenUpdateSql ¶
func NewCurTime ¶ added in v0.0.2
Types ¶
type DB ¶
type DBOption ¶ added in v0.0.2
type DBOption func(*DBOptions)
func WithConnMaxIdletime ¶
func WithConnMaxLifetime ¶
func WithContext ¶
func WithDirver ¶
func WithIgnoreNotFound ¶
func WithIgnoreNotFound() DBOption
func WithMaxIdleCount ¶
func WithMaxOpenConns ¶
func WithMaxRows ¶
func WithoutPing ¶
func WithoutPing() DBOption
type DBOptions ¶ added in v0.0.2
type DBOptions struct {
// contains filtered or unexported fields
}
type Driver ¶ added in v0.0.2
type Driver interface { // refer: https://gorm.io/docs/migration.html AutoMigrate(sample interface{}, opts ...Option) error // parse datatype ParseField(opts *StructField) // Database CurrentDatabase() string FullDataTypeOf(field *StructField) string // Tables CreateTable(o *Options) error DropTable(o *Options) error HasTable(tableName string) bool GetTables() (tableList []string, err error) // Columns AddColumn(field string, o *Options) error DropColumn(field string, o *Options) error AlterColumn(field string, o *Options) error MigrateColumn(expect, actual *StructField, o *Options) error HasColumn(field string, o *Options) bool ColumnTypes(o *Options) ([]StructField, error) // Indexes CreateIndex(name string, o *Options) error DropIndex(name string, o *Options) error HasIndex(name string, o *Options) bool }
type Execer ¶ added in v0.0.2
type Execer interface { Exec(query string, args ...interface{}) (sql.Result, error) ExecLastId(sql string, args ...interface{}) (int64, error) ExecNum(sql string, args ...interface{}) (int64, error) ExecNumErr(s string, args ...interface{}) error Query(query string, args ...interface{}) *Rows WithRawDB(raw RawDB) Interface RawDB() RawDB }
type Option ¶
type Option func(*Options)
func WithIgnoreNotFoundErr ¶ added in v0.0.2
func WithIgnoreNotFoundErr() Option
func WithOrderby ¶ added in v0.0.2
func WithSample ¶
func WithSample(sample interface{}) Option
func WithSelector ¶ added in v0.0.2
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func NewOptions ¶ added in v0.0.2
func (*Options) GenDeleteSql ¶ added in v0.0.2
TODO: generate selector from sample.fields, like GenUpdateSql
func (*Options) GenInsertSql ¶ added in v0.0.2
func (*Options) GenListSql ¶ added in v0.0.2
func (*Options) GenUpdateSql ¶ added in v0.0.2
type Rows ¶
type Rows struct { *DBOptions // contains filtered or unexported fields }
type Set ¶ added in v0.0.2
Set is a map of field:value. It implements Fields.
func ParseFields ¶ added in v0.0.2
type Store ¶ added in v0.0.2
type Store interface { Insert(sample interface{}, opts ...Option) error InsertLastId(sample interface{}, opts ...Option) (int64, error) Get(into interface{}, opts ...Option) error List(into interface{}, opts ...Option) error Update(sample interface{}, opts ...Option) error Delete(sample interface{}, opts ...Option) error }
type StructField ¶ added in v0.0.2
type StructField struct { Set Type reflect.Type Index []int FieldName string Name string Where bool Skip bool Inline bool // from tag DataType DataType AutoCreatetime TimeType // auto_createtime AutoUpdatetime TimeType // auto_updatetime PrimaryKey bool AutoIncrement bool AutoIncrementNum int64 HasDefaultValue bool DefaultValue string DefaultValueInterface interface{} Size *int64 Precision *int64 Scale *int64 NotNull *bool Unique *bool Comment *string // index IndexComment string IndexClass string IndexOption string IndexKey bool IndexName string DriverDataType string Class string }
func GetField ¶ added in v0.0.2
func GetField(sample interface{}, field string, driver Driver) *StructField
func (StructField) String ¶ added in v0.0.2
func (p StructField) String() string
type StructFields ¶ added in v0.0.2
type StructFields struct { Fields []*StructField // contains filtered or unexported fields }
func GetFields ¶ added in v0.0.2
func GetFields(sample interface{}, driver Driver) StructFields
func (StructFields) String ¶ added in v0.0.2
func (p StructFields) String() (ret string)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.