Documentation
¶
Index ¶
- Constants
- Variables
- func GetDB[T any](appDB AppIDB) T
- func SetConnectionsPool(db *sql.DB, pool *DbPoolOptions)
- func SortSQL(param *SortParam) (string, error)
- type AppIDB
- type DB
- type DBTx
- type DbPoolOptions
- type Limit
- type SQLQueryBuilder
- func (bd *SQLQueryBuilder) AddParam(params ...interface{}) *SQLQueryBuilder
- func (bd *SQLQueryBuilder) AddQuery(sql string) *SQLQueryBuilder
- func (bd *SQLQueryBuilder) AddQueryWithParam(sql string, params ...interface{}) *SQLQueryBuilder
- func (bd *SQLQueryBuilder) GetQueryParams() []interface{}
- func (bd *SQLQueryBuilder) ToSQLQuery() string
- type Sort
- type SortParam
- type TxFn
- type WhereBuilder
- type WhereCause
Constants ¶
View Source
const ( ASC = "ASC" DESC = "DESC" )
View Source
const ( Or = 2 And = 1 )
Variables ¶
View Source
var DbPoolDefault = &DbPoolOptions{ MaxIdleConns: 5, MaxOpenConns: 10, ConnMaxLifetime: 10 * time.Minute, }
Functions ¶
func SetConnectionsPool ¶
func SetConnectionsPool(db *sql.DB, pool *DbPoolOptions)
Types ¶
type DB ¶ added in v1.0.10
type DB[T any] interface { WithTx(tx AppIDB) DB[T] RawExec(ctx context.Context, sqlQuery string, params []interface{}) (int64, error) RawQuery(ctx context.Context, sql string, params []interface{}, resultPtr interface{}) error Create(ctx context.Context, obj *T) (*T, error) CreateList(ctx context.Context, obj *[]T) (*[]T, error) Update(ctx context.Context, obj *T) (*T, error) UpdateList(ctx context.Context, obj *[]T) (*[]T, error) Upsert(ctx context.Context, obj *T, specifyUpdateFields []string) (*T, error) UpsertList(ctx context.Context, obj *[]T, specifyUpdateFields []string) (*[]T, error) UpdateForce(ctx context.Context, obj *T) (*T, error) FindByPK(ctx context.Context, obj *T) (*T, error) Delete(ctx context.Context, obj *T) error DeleteList(ctx context.Context, obj *[]T) error DeleteWhere(ctx context.Context, whereCauses *[]WhereCause) error Count(ctx context.Context, whereObj *T) (int64, error) List(ctx context.Context, whereObj *T) (*[]T, error) ListWhere(ctx context.Context, whereCauses *[]WhereCause, limit *Limit, sortBy []string) (*[]T, error) QueryListWhere(ctx context.Context, whereCauses *[]WhereCause, limit *Limit, sortBy []string) (*[]T, int64, error) FirstWhere(ctx context.Context, whereCauses *[]WhereCause, sortBy []string) (*T, error) FindOneWhere(ctx context.Context, whereCauses *[]WhereCause) (*T, error) FindOne(ctx context.Context, whereObj *T) (*T, error) CountWhere(ctx context.Context, whereCauses *[]WhereCause) (int64, error) }
type DbPoolOptions ¶
type DbPoolOptions struct {
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
MaxIdleConns int
// SetMaxOpenConns sets the maximum number of open connections to the database.
MaxOpenConns int
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
ConnMaxLifetime time.Duration
}
type SQLQueryBuilder ¶
type SQLQueryBuilder struct {
// contains filtered or unexported fields
}
func NewSQLQueryBuilder ¶
func NewSQLQueryBuilder() SQLQueryBuilder
func (*SQLQueryBuilder) AddParam ¶
func (bd *SQLQueryBuilder) AddParam(params ...interface{}) *SQLQueryBuilder
func (*SQLQueryBuilder) AddQuery ¶
func (bd *SQLQueryBuilder) AddQuery(sql string) *SQLQueryBuilder
func (*SQLQueryBuilder) AddQueryWithParam ¶
func (bd *SQLQueryBuilder) AddQueryWithParam(sql string, params ...interface{}) *SQLQueryBuilder
func (*SQLQueryBuilder) GetQueryParams ¶
func (bd *SQLQueryBuilder) GetQueryParams() []interface{}
func (*SQLQueryBuilder) ToSQLQuery ¶
func (bd *SQLQueryBuilder) ToSQLQuery() string
type WhereBuilder ¶ added in v1.0.10
type WhereBuilder struct {
// contains filtered or unexported fields
}
func NewWhereBuilder ¶ added in v1.0.10
func NewWhereBuilder() *WhereBuilder
func (*WhereBuilder) Where ¶ added in v1.0.10
func (w *WhereBuilder) Where(query string, args ...interface{}) *WhereBuilder
func (*WhereBuilder) WhereCauses ¶ added in v1.0.10
func (w *WhereBuilder) WhereCauses() *[]WhereCause
func (*WhereBuilder) WhereOr ¶ added in v1.0.10
func (w *WhereBuilder) WhereOr(query string, args ...interface{}) *WhereBuilder
type WhereCause ¶ added in v1.0.10
Click to show internal directories.
Click to hide internal directories.
