Documentation ¶
Index ¶
- Variables
- func Column(tableName, columnName string) string
- func ColumnAlias(tableName, columnName, alias string) string
- func EmptySlice(s any) bool
- func FromMap(m any) bool
- func FromSlice(s any) bool
- func JoinSubQueryAlias(query *gorm.DB, alias string) string
- func NewExecuteSqlError(sql string, errorOccurred error) error
- func NewTemplateFormatError(template []rune) error
- func Receivable(v any) bool
- type BaseDatabaseImplement
- func (s *BaseDatabaseImplement) Count(table, query string, args ...any) (count int64, err error)
- func (s *BaseDatabaseImplement) CountWithCtx(ctx context.Context, table, query string, args ...any) (count int64, err error)
- func (s *BaseDatabaseImplement) DeleteAll(query string, args ...any) error
- func (s *BaseDatabaseImplement) DeleteAllWithCtx(ctx context.Context, query string, args ...any) error
- func (s *BaseDatabaseImplement) DeleteOne(query string, args ...any) error
- func (s *BaseDatabaseImplement) DeleteOneWithCtx(ctx context.Context, query string, args ...any) error
- func (s *BaseDatabaseImplement) ExecRaw(sql string, args ...any) error
- func (s *BaseDatabaseImplement) ExecRawWithCtx(ctx context.Context, sql string, args ...any) error
- func (s *BaseDatabaseImplement) ExtMethods() ExtMethods
- func (s *BaseDatabaseImplement) GetAll(receiver any, query string, args ...any) error
- func (s *BaseDatabaseImplement) GetAllWithCtx(ctx context.Context, receiver any, query string, args ...any) error
- func (s *BaseDatabaseImplement) GetOne(receiver any, query string, args ...any) error
- func (s *BaseDatabaseImplement) GetOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error
- func (s *BaseDatabaseImplement) GetPage(receiver any, offset, limit int, query string, args ...any) error
- func (s *BaseDatabaseImplement) Has(table, query string, args ...any) (exist bool, err error)
- func (s *BaseDatabaseImplement) HasWithCtx(ctx context.Context, table, query string, args ...any) (exist bool, err error)
- func (s *BaseDatabaseImplement) Init(_ Options) error
- func (s *BaseDatabaseImplement) InsertAll(data any) error
- func (s *BaseDatabaseImplement) InsertAllWithCtx(ctx context.Context, data any) error
- func (s *BaseDatabaseImplement) InsertOne(data any) error
- func (s *BaseDatabaseImplement) InsertOneWithCtx(ctx context.Context, data any) error
- func (s *BaseDatabaseImplement) Migrate(models ...any) error
- func (s *BaseDatabaseImplement) ParseDatabaseOptions(db *sql.DB, opts Options)
- func (s *BaseDatabaseImplement) PickAll(receiver any, length int, query string, args ...any) error
- func (s *BaseDatabaseImplement) PickAllWithCtx(ctx context.Context, receiver any, length int, query string, args ...any) error
- func (s *BaseDatabaseImplement) PickOne(receiver any, query string, args ...any) error
- func (s *BaseDatabaseImplement) PickOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error
- func (s *BaseDatabaseImplement) QueryRaw(receiver any, sql string, args ...any) error
- func (s *BaseDatabaseImplement) QueryRawWithCtx(ctx context.Context, receiver any, sql string, args ...any) error
- func (s *BaseDatabaseImplement) SetDriverName(name string)
- func (s *BaseDatabaseImplement) SetLogger(logger logger.Logger)
- func (s *BaseDatabaseImplement) SetRandCommand(command string)
- func (s *BaseDatabaseImplement) UpdateAll(data any, query string, args ...any) error
- func (s *BaseDatabaseImplement) UpdateAllWithCtx(ctx context.Context, data any, query string, args ...any) error
- func (s *BaseDatabaseImplement) UpdateOne(data any, query string, args ...any) error
- func (s *BaseDatabaseImplement) UpdateOneWithCtx(ctx context.Context, data any, query string, args ...any) error
- type BaseDatabaseImplementV2
- func (v2 *BaseDatabaseImplementV2) CreateDataOnDuplicateKeyUpdate(ctx context.Context, data any, indexKeys, updateFields []string) error
- func (v2 *BaseDatabaseImplementV2) CreateSingleDataIfNotExist(ctx context.Context, data any) (created bool, err error)
- func (v2 *BaseDatabaseImplementV2) ExecuteRawSql(ctx context.Context, sql string) error
- func (v2 *BaseDatabaseImplementV2) ExecuteRawSqlQuery(ctx context.Context, receiver any, sql string) error
- func (v2 *BaseDatabaseImplementV2) ExecuteRawSqlTemplate(ctx context.Context, sql string, template RawSqlTemplate) error
- func (v2 *BaseDatabaseImplementV2) ExecuteRawSqlTemplateQuery(ctx context.Context, receiver any, sql string, template RawSqlTemplate) error
- func (v2 *BaseDatabaseImplementV2) GetDataByCustomCondition(ctx context.Context, receiver, condition any, needFields ...string) error
- func (v2 *BaseDatabaseImplementV2) GetDataBySingleCondition(ctx context.Context, receiver any, column string, condition any, ...) error
- func (v2 *BaseDatabaseImplementV2) GetGormCore(ctx context.Context) *gorm.DB
- func (v2 *BaseDatabaseImplementV2) ListDataWithPage(ctx context.Context, receiver any, filter any, order string, desc bool, ...) error
- func (v2 *BaseDatabaseImplementV2) UpdateDataByCustomCondition(ctx context.Context, updates, condition any) error
- func (v2 *BaseDatabaseImplementV2) UpdateDataBySingleCondition(ctx context.Context, updates any, column string, condition any) error
- type BaseExtMethodGroup
- func (b *BaseExtMethodGroup) DriverName() string
- func (b *BaseExtMethodGroup) Exec(cmd func(db *gorm.DB) *gorm.DB) error
- func (b *BaseExtMethodGroup) ExecCtx(ctx context.Context, cmd func(db *gorm.DB) *gorm.DB) error
- func (b *BaseExtMethodGroup) GetGorm() *gorm.DB
- func (b *BaseExtMethodGroup) Transaction(cmd func(tx *gorm.DB) error) error
- func (b *BaseExtMethodGroup) TransactionCtx(ctx context.Context, cmd func(tx *gorm.DB) error) error
- type DBLogger
- func (dl *DBLogger) Error(ctx context.Context, s string, i ...interface{})
- func (dl *DBLogger) Info(ctx context.Context, s string, i ...interface{})
- func (dl *DBLogger) LogMode(level glog.LogLevel) glog.Interface
- func (dl *DBLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (dl *DBLogger) Warn(ctx context.Context, s string, i ...interface{})
- type Databasedeprecated
- type DatabaseV2
- type ExecuteSqlError
- type ExtMethods
- type Extended
- type Extension
- type Options
- type RawSqlTemplate
- type TemplateFormatError
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidCondition = errors.New("invalid condition") ErrInvalidSingleData = errors.New("invalid single data") )
Functions ¶
func ColumnAlias ¶ added in v1.2.18
func EmptySlice ¶ added in v1.2.18
func JoinSubQueryAlias ¶ added in v1.2.18
func NewExecuteSqlError ¶ added in v1.2.10
func NewTemplateFormatError ¶ added in v1.2.10
func Receivable ¶ added in v1.2.18
Types ¶
type BaseDatabaseImplement ¶
type BaseDatabaseImplement struct { Db *gorm.DB Logger logger.Logger Timeout time.Duration // contains filtered or unexported fields }
func (*BaseDatabaseImplement) Count ¶
func (s *BaseDatabaseImplement) Count(table, query string, args ...any) (count int64, err error)
func (*BaseDatabaseImplement) CountWithCtx ¶
func (*BaseDatabaseImplement) DeleteAll ¶
func (s *BaseDatabaseImplement) DeleteAll(query string, args ...any) error
func (*BaseDatabaseImplement) DeleteAllWithCtx ¶
func (*BaseDatabaseImplement) DeleteOne ¶
func (s *BaseDatabaseImplement) DeleteOne(query string, args ...any) error
func (*BaseDatabaseImplement) DeleteOneWithCtx ¶
func (*BaseDatabaseImplement) ExecRaw ¶
func (s *BaseDatabaseImplement) ExecRaw(sql string, args ...any) error
func (*BaseDatabaseImplement) ExecRawWithCtx ¶
func (*BaseDatabaseImplement) ExtMethods ¶ added in v1.2.7
func (s *BaseDatabaseImplement) ExtMethods() ExtMethods
func (*BaseDatabaseImplement) GetAll ¶
func (s *BaseDatabaseImplement) GetAll(receiver any, query string, args ...any) error
func (*BaseDatabaseImplement) GetAllWithCtx ¶
func (*BaseDatabaseImplement) GetOne ¶
func (s *BaseDatabaseImplement) GetOne(receiver any, query string, args ...any) error
func (*BaseDatabaseImplement) GetOneWithCtx ¶
func (*BaseDatabaseImplement) Has ¶
func (s *BaseDatabaseImplement) Has(table, query string, args ...any) (exist bool, err error)
func (*BaseDatabaseImplement) HasWithCtx ¶
func (*BaseDatabaseImplement) Init ¶
func (s *BaseDatabaseImplement) Init(_ Options) error
func (*BaseDatabaseImplement) InsertAll ¶
func (s *BaseDatabaseImplement) InsertAll(data any) error
func (*BaseDatabaseImplement) InsertAllWithCtx ¶
func (s *BaseDatabaseImplement) InsertAllWithCtx(ctx context.Context, data any) error
func (*BaseDatabaseImplement) InsertOne ¶
func (s *BaseDatabaseImplement) InsertOne(data any) error
func (*BaseDatabaseImplement) InsertOneWithCtx ¶
func (s *BaseDatabaseImplement) InsertOneWithCtx(ctx context.Context, data any) error
func (*BaseDatabaseImplement) Migrate ¶
func (s *BaseDatabaseImplement) Migrate(models ...any) error
func (*BaseDatabaseImplement) ParseDatabaseOptions ¶
func (s *BaseDatabaseImplement) ParseDatabaseOptions(db *sql.DB, opts Options)
func (*BaseDatabaseImplement) PickAllWithCtx ¶
func (*BaseDatabaseImplement) PickOne ¶
func (s *BaseDatabaseImplement) PickOne(receiver any, query string, args ...any) error
func (*BaseDatabaseImplement) PickOneWithCtx ¶
func (*BaseDatabaseImplement) QueryRaw ¶
func (s *BaseDatabaseImplement) QueryRaw(receiver any, sql string, args ...any) error
func (*BaseDatabaseImplement) QueryRawWithCtx ¶
func (*BaseDatabaseImplement) SetDriverName ¶ added in v1.2.7
func (s *BaseDatabaseImplement) SetDriverName(name string)
func (*BaseDatabaseImplement) SetLogger ¶ added in v1.2.10
func (s *BaseDatabaseImplement) SetLogger(logger logger.Logger)
func (*BaseDatabaseImplement) SetRandCommand ¶
func (s *BaseDatabaseImplement) SetRandCommand(command string)
func (*BaseDatabaseImplement) UpdateAll ¶
func (s *BaseDatabaseImplement) UpdateAll(data any, query string, args ...any) error
func (*BaseDatabaseImplement) UpdateAllWithCtx ¶
func (*BaseDatabaseImplement) UpdateOne ¶
func (s *BaseDatabaseImplement) UpdateOne(data any, query string, args ...any) error
func (*BaseDatabaseImplement) UpdateOneWithCtx ¶
type BaseDatabaseImplementV2 ¶ added in v1.2.18
func (*BaseDatabaseImplementV2) CreateDataOnDuplicateKeyUpdate ¶ added in v1.2.18
func (*BaseDatabaseImplementV2) CreateSingleDataIfNotExist ¶ added in v1.2.18
func (*BaseDatabaseImplementV2) ExecuteRawSql ¶ added in v1.2.18
func (v2 *BaseDatabaseImplementV2) ExecuteRawSql(ctx context.Context, sql string) error
func (*BaseDatabaseImplementV2) ExecuteRawSqlQuery ¶ added in v1.2.18
func (*BaseDatabaseImplementV2) ExecuteRawSqlTemplate ¶ added in v1.2.18
func (v2 *BaseDatabaseImplementV2) ExecuteRawSqlTemplate(ctx context.Context, sql string, template RawSqlTemplate) error
func (*BaseDatabaseImplementV2) ExecuteRawSqlTemplateQuery ¶ added in v1.2.18
func (v2 *BaseDatabaseImplementV2) ExecuteRawSqlTemplateQuery(ctx context.Context, receiver any, sql string, template RawSqlTemplate) error
func (*BaseDatabaseImplementV2) GetDataByCustomCondition ¶ added in v1.2.18
func (*BaseDatabaseImplementV2) GetDataBySingleCondition ¶ added in v1.2.18
func (*BaseDatabaseImplementV2) GetGormCore ¶ added in v1.2.18
func (v2 *BaseDatabaseImplementV2) GetGormCore(ctx context.Context) *gorm.DB
func (*BaseDatabaseImplementV2) ListDataWithPage ¶ added in v1.2.18
func (*BaseDatabaseImplementV2) UpdateDataByCustomCondition ¶ added in v1.2.18
func (v2 *BaseDatabaseImplementV2) UpdateDataByCustomCondition(ctx context.Context, updates, condition any) error
func (*BaseDatabaseImplementV2) UpdateDataBySingleCondition ¶ added in v1.2.18
type BaseExtMethodGroup ¶ added in v1.2.7
type BaseExtMethodGroup struct {
// contains filtered or unexported fields
}
func (*BaseExtMethodGroup) DriverName ¶ added in v1.2.7
func (b *BaseExtMethodGroup) DriverName() string
func (*BaseExtMethodGroup) GetGorm ¶ added in v1.2.7
func (b *BaseExtMethodGroup) GetGorm() *gorm.DB
func (*BaseExtMethodGroup) Transaction ¶ added in v1.2.10
func (b *BaseExtMethodGroup) Transaction(cmd func(tx *gorm.DB) error) error
func (*BaseExtMethodGroup) TransactionCtx ¶ added in v1.2.10
type DBLogger ¶ added in v1.2.19
type DBLogger struct {
// contains filtered or unexported fields
}
func NewDBLogger ¶ added in v1.2.19
type Database
deprecated
type Database interface { Init(options Options) error Migrate(models ...any) error Has(table string, query string, args ...any) (exist bool, err error) Count(table string, query string, args ...any) (count int64, err error) GetOne(receiver any, query string, args ...any) error GetAll(receiver any, query string, args ...any) error GetPage(receiver any, offset, limit int, query string, args ...any) error PickOne(receiver any, query string, args ...any) error PickAll(receiver any, length int, query string, args ...any) error InsertOne(data any) error InsertAll(data any) error UpdateOne(data any, query string, args ...any) error UpdateAll(data any, query string, args ...any) error DeleteOne(query string, args ...any) error DeleteAll(query string, args ...any) error ExecRaw(sql string, args ...any) error QueryRaw(receiver any, sql string, args ...any) error HasWithCtx(ctx context.Context, table string, query string, args ...any) (exist bool, err error) CountWithCtx(ctx context.Context, table string, query string, args ...any) (count int64, err error) GetOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error GetAllWithCtx(ctx context.Context, receiver any, query string, args ...any) error PickOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error PickAllWithCtx(ctx context.Context, receiver any, length int, query string, args ...any) error InsertOneWithCtx(ctx context.Context, data any) error InsertAllWithCtx(ctx context.Context, data any) error UpdateOneWithCtx(ctx context.Context, data any, query string, args ...any) error UpdateAllWithCtx(ctx context.Context, data any, query string, args ...any) error DeleteOneWithCtx(ctx context.Context, query string, args ...any) error DeleteAllWithCtx(ctx context.Context, query string, args ...any) error ExecRawWithCtx(ctx context.Context, sql string, args ...any) error QueryRawWithCtx(ctx context.Context, receiver any, sql string, args ...any) error ExtMethods() ExtMethods SetLogger(logger logger.Logger) }
Database is the interface that wraps the basic database operations. The implementation of this interface should be thread-safe.
Deprecated: Use DatabaseV2 instead.
type DatabaseV2 ¶ added in v1.2.18
type DatabaseV2 interface { // GetGormCore retrieves the core *gorm.DB instance with the provided context. // // Parameters: // ctx (context.Context): The context for the database operation. // // Returns: // *gorm.DB: The GORM database instance with the provided context. GetGormCore(ctx context.Context) *gorm.DB // GetDataBySingleCondition retrieves data from the database based on a single column condition. // The result is stored in the receiver. // // Parameters: // ctx (context.Context): The context for the database operation. // receiver (any): The destination where the query result will be stored. // column (string): The column name to apply the condition. // condition (any): The condition value for the specified column. // needFields (...string): Optional fields to select in the query. // // Returns: // error: An error if the operation fails, otherwise nil. GetDataBySingleCondition(ctx context.Context, receiver any, column string, condition any, needFields ...string) error // GetDataByCustomCondition retrieves data from the database based on a custom condition. // The result is stored in the receiver. // // Parameters: // ctx (context.Context): The context for the database operation. // receiver (any): The destination where the query result will be stored. // condition (any): The custom condition for the query. // needFields (...string): Optional fields to select in the query. // // Returns: // error: An error if the operation fails, otherwise nil. GetDataByCustomCondition(ctx context.Context, receiver, condition any, needFields ...string) error // ListDataWithPage retrieves a paginated list of data from the database based on the provided filter and ordering. // The result is stored in the receiver. // // Parameters: // ctx (context.Context): The context for the database operation. // receiver (any): The destination where the query result will be stored. // filter (any): The filter condition for the query. // order (string): The column name to order by. // desc (bool): Whether to order in descending order. // offset (int): The offset for pagination. // limit (int): The limit for pagination. // needFields (...string): Optional fields to select in the query. // // Returns: // error: An error if the operation fails, otherwise nil. ListDataWithPage(ctx context.Context, receiver any, filter any, order string, desc bool, offset, limit int, needFields ...string) error // CreateSingleDataIfNotExist creates a single data record in the database if it does not already exist. // // Parameters: // ctx (context.Context): The context for the database operation. // data (any): The data record to be created. // // Returns: // created (bool): True if the data record was created, false if it already exists. // err (error): An error if the operation fails, otherwise nil. CreateSingleDataIfNotExist(ctx context.Context, data any) (created bool, err error) // CreateDataOnDuplicateKeyUpdate creates a data record in the database or updates it if a duplicate key is found. // // Parameters: // ctx (context.Context): The context for the database operation. // data (any): The data record to be created or updated. // indexKeys ([]string): The index keys to check for duplication. // updateFields ([]string): The fields to update if a duplicate key is found. // // Returns: // error: An error if the operation fails, otherwise nil. CreateDataOnDuplicateKeyUpdate(ctx context.Context, data any, indexKeys, updateFields []string) error // UpdateDataBySingleCondition updates data in the database based on a single column condition. // // Parameters: // ctx (context.Context): The context for the database operation. // updates (any): The data to be updated. // column (string): The column name to apply the condition. // condition (any): The condition value for the specified column. // // Returns: // error: An error if the operation fails, otherwise nil. UpdateDataBySingleCondition(ctx context.Context, updates any, column string, condition any) error // UpdateDataByCustomCondition updates data in the database based on a custom condition. // // Parameters: // ctx (context.Context): The context for the database operation. // updates (any): The data to be updated. // condition (any): The custom condition for the query. // // Returns: // error: An error if the operation fails, otherwise nil. UpdateDataByCustomCondition(ctx context.Context, updates, condition any) error // ExecuteRawSqlTemplateQuery executes a raw SQL template query with the provided context. // // Parameters: // ctx (context.Context): The context for the database operation. // receiver (any): The destination where the query result will be stored. // sql (string): The raw SQL template to execute. // template (RawSqlTemplate): The raw SQL template value to execute. // // Returns: // error: An error if the operation fails, otherwise nil. ExecuteRawSqlTemplateQuery(ctx context.Context, receiver any, sql string, template RawSqlTemplate) error // ExecuteRawSqlTemplate executes a raw SQL template with the provided context. // // Parameters: // ctx (context.Context): The context for the database operation. // sql (string): The raw SQL template to execute. // template (RawSqlTemplate): The raw SQL template value to execute. // // Returns: // error: An error if the operation fails, otherwise nil. ExecuteRawSqlTemplate(ctx context.Context, sql string, template RawSqlTemplate) error // ExecuteRawSqlQuery executes a raw SQL query with the provided context. // // Parameters: // ctx (context.Context): The context for the database operation. // receiver (any): The destination where the query result will be stored. // sql (string): The raw SQL to execute. // // Returns: // error: An error if the operation fails, otherwise nil. ExecuteRawSqlQuery(ctx context.Context, receiver any, sql string) error // ExecuteRawSql executes a raw SQL with the provided context. // // Parameters: // ctx (context.Context): The context for the database operation. // sql (string): The raw SQL to execute. // // Returns: // error: An error if the operation fails, otherwise nil. ExecuteRawSql(ctx context.Context, sql string) error }
DatabaseV2 is the interface that wraps the basic database operations. The implementation of this interface should be thread-safe.
type ExecuteSqlError ¶ added in v1.2.10
func (*ExecuteSqlError) Error ¶ added in v1.2.10
func (err *ExecuteSqlError) Error() string
type ExtMethods ¶ added in v1.2.7
type RawSqlTemplate ¶ added in v1.2.18
type TemplateFormatError ¶ added in v1.2.10
type TemplateFormatError struct {
Template string `json:"template"`
}
func (*TemplateFormatError) Error ¶ added in v1.2.10
func (err *TemplateFormatError) Error() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.