orm

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DateLayout = "2006-01-02"
View Source
var DateTimeLayout = "2006-01-02 15:04"
View Source
var ErrScanResultTypeUnsupported = fmt.Errorf("scan result type unsupported")
View Source
var (
	Indexers = make(map[string]func())
)
View Source
var TimeLayout = "15:04"

Functions

func Decode

func Decode(src string) string

func Encode

func Encode(src string) string

func EnsureAllIndex

func EnsureAllIndex(fns ...IndexOptionsHandler) error

func GetPostHooks added in v0.0.5

func GetPostHooks(name string, className string) (func(), bool)

func I32Time

func I32Time(c int32) string

func I64Date

func I64Date(c int64) string

func I64DateTime

func I64DateTime(c int64) string

func I64Time

func I64Time(c int64) string

func IndexKey

func IndexKey(i any) string

func IsErrNotFound

func IsErrNotFound(err error) bool

IsErrorNotFound is a sql.ErrNoRows wrapper

func MsSQLOffsetLimit

func MsSQLOffsetLimit(offset, limit int) string

func MsSQLTimeFormat

func MsSQLTimeFormat(t interface{}) string

func MsSQLTimeParse

func MsSQLTimeParse(s string) time.Time

func NewStringSlice

func NewStringSlice(len int, val string) []string

func PrintToJson

func PrintToJson(obj interface{})

func RegisterEzOrmObj

func RegisterEzOrmObj(namespace, classname string, constructor func() EzOrmObj)

func RegisterEzOrmObjByID

func RegisterEzOrmObjByID(namespace, classname string, f func(id string) (result EzOrmObj, err error))

func RegisterEzOrmObjRemove

func RegisterEzOrmObjRemove(namespace, classname string, f func(id string) (err error))

func RegisterIndexer

func RegisterIndexer(namespace, classname string, indexer func())

func RegisterSetupPostHooks

func RegisterSetupPostHooks(name string, className string, fn func())

func RemoveEzOrmObj

func RemoveEzOrmObj(namespace, classname, id string) (err error)

func SQLOffsetLimit

func SQLOffsetLimit(offset, limit int) string

func SQLOrderBy

func SQLOrderBy(field string, revert bool) string

func SQLWhere

func SQLWhere(conditions []string) string

func SetupIndexModel

func SetupIndexModel(c *mongo.Collection, keys []mongo.IndexModel)

func SliceJoin

func SliceJoin(objs []interface{}, sep string) string

func StringScan

func StringScan(str string, v interface{}) error

func TimeFormat

func TimeFormat(t time.Time) string

func TimeParse

func TimeParse(s string) time.Time

func TimeParseLocalTime

func TimeParseLocalTime(s string) time.Time

func TimeToLocalTime

func TimeToLocalTime(c time.Time) string

func ToFloat64

func ToFloat64(value interface{}) (float64, error)

func ToJsonString

func ToJsonString(obj interface{}) string

func ToResult added in v0.0.8

func ToResult[T Result](rawField any) (T, error)

Inspired by https://github.com/go-sql-driver/mysql/issues/86, if the Go SQL driver cannot determine the underlying type of scan result(`interface{}` or `any`), it will fallback to TEXT protocol to communicate with MySQL server, therefore, the result can only be `[]uint8`(`[]byte`) or raw `string`. But the behavior differs from drivers.

func Transact

func Transact(db *DBStore, t Transactor) error

func TransactFunc

func TransactFunc(db *DBStore, txFunc func(*DBTx) error) (err error)

func UniqURLParams

func UniqURLParams(url_ string) string

func XGetMoreSearchObj

func XGetMoreSearchObj(word string, fields []string, params map[string]interface{}, termKeys map[string]bool, dateKeys map[string]bool) map[string]interface{}

func XGetQuery

func XGetQuery(key string, data map[string]interface{}) map[string]interface{}

func XGetQueryString

func XGetQueryString(word string, fields []string) map[string]interface{}

func XGetSearchObj

func XGetSearchObj(word string, fields []string, params map[string]string, termKeys map[string]bool, dateKeys map[string]bool) map[string]interface{}

func XSortFieldsFilter

func XSortFieldsFilter(sortFields []string) (rtn []string)

Types

type DB

type DB interface {
	Query(ctx context.Context, sql string, args ...interface{}) (*sql.Rows, error)
	Exec(ctx context.Context, sql string, args ...interface{}) (sql.Result, error)
	SetError(err error)
}

type DBStore

type DBStore struct {
	*sql.DB
	// contains filtered or unexported fields
}

func NewDBDSNStore

func NewDBDSNStore(driver, dsn string) (*DBStore, error)

func NewDBStore

func NewDBStore(driver, host string, port int, database, username, password string) (*DBStore, error)

func NewDBStoreCharset

func NewDBStoreCharset(driver, host string, port int, databaseName, username, password, charset string) (*DBStore, error)

func NewDBStoreWithRawDB

func NewDBStoreWithRawDB(db *sql.DB) *DBStore

func (*DBStore) AddWrappers

func (store *DBStore) AddWrappers(wp ...database.Wrapper)

func (*DBStore) BeginTx

func (store *DBStore) BeginTx() (*DBTx, error)

func (*DBStore) Close

func (store *DBStore) Close() error

func (*DBStore) Debug

func (store *DBStore) Debug(b bool)

func (*DBStore) Exec

func (store *DBStore) Exec(ctx context.Context, query string,
	args ...interface{}) (sql.Result, error)

func (*DBStore) Query

func (store *DBStore) Query(ctx context.Context, query string,
	args ...interface{}) (*sql.Rows, error)

func (*DBStore) SetError

func (store *DBStore) SetError(err error)

func (*DBStore) SlowLog

func (store *DBStore) SlowLog(duration time.Duration)

type DBTx

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

func (*DBTx) Close

func (tx *DBTx) Close() error

func (*DBTx) Exec

func (tx *DBTx) Exec(ctx context.Context, query string,
	args ...interface{}) (sql.Result, error)

func (*DBTx) IsRollback

func (tx *DBTx) IsRollback() bool

func (*DBTx) Query

func (tx *DBTx) Query(ctx context.Context, query string,
	args ...interface{}) (*sql.Rows, error)

func (*DBTx) SetError

func (tx *DBTx) SetError(err error)

type EzOrmObj

type EzOrmObj interface {
	Id() string
	GetClassName() string
	GetNameSpace() string
}

func NewEzOrmObjByID

func NewEzOrmObjByID(namespace, classname, id string) (result EzOrmObj, err error)

func NewEzOrmObjObj

func NewEzOrmObjObj(namespace, classname string) EzOrmObj

type FieldIN

type FieldIN struct {
	Field  string
	Params []interface{}
	// contains filtered or unexported fields
}

func NewFieldIN

func NewFieldIN(field string) *FieldIN

func (*FieldIN) Add

func (in *FieldIN) Add(v interface{}) *FieldIN

func (*FieldIN) SQLFormat

func (in *FieldIN) SQLFormat() string

func (*FieldIN) SQLParams

func (in *FieldIN) SQLParams() []interface{}

type FieldMultiIN

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

func NewMultiFieldIN

func NewMultiFieldIN(fields []string) *FieldMultiIN

func (*FieldMultiIN) Add

func (in *FieldMultiIN) Add(v []interface{}) error

func (*FieldMultiIN) SQLFormat

func (in *FieldMultiIN) SQLFormat() string

func (*FieldMultiIN) SQLParams

func (in *FieldMultiIN) SQLParams() []interface{}

type IndexModifier

type IndexModifier struct {
	Key    bson.D
	Option *options.IndexOptions
	Result IndexResult
}

type IndexOptionsHandler

type IndexOptionsHandler func(im *IndexModifier) error

func IndexCreateResult added in v0.0.6

func IndexCreateResult(exist *int, created *int) IndexOptionsHandler

func WithIndexNameHandler

func WithIndexNameHandler(index bson.D, opt *options.IndexOptions) IndexOptionsHandler

type IndexResult added in v0.0.6

type IndexResult struct {
	ExistsIndex  int
	CreatedIndex int
}

type Result added in v0.0.8

type Result interface {
	sql.NullInt64 | sql.NullString
}

type SearchObj

type SearchObj interface {
	IsSearchEnabled() bool
	GetSearchTip() string
}

type Transactor

type Transactor interface {
	Transact(tx *DBTx) error
}

Jump to

Keyboard shortcuts

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