Documentation
¶
Index ¶
- Constants
- func DatabaseEscapeCharacters(typ types.DatabaseType) (string, string)
- func RegistryDialectFactory(t types.DatabaseType, factory func(DatabaseProperties) gorm.Dialector)
- type Criteria
- func (c *Criteria) Asc(cols ...types.ColumnName) *Criteria
- func (c *Criteria) Between(col types.ColumnName, min, max any) *Criteria
- func (c *Criteria) Build() *gorm.DB
- func (c *Criteria) BuildQuery(sql *string) (statement string, args []any)
- func (c *Criteria) BuildWithContext(ctx context.Context) *gorm.DB
- func (c *Criteria) BuildWithTx(tx *gorm.DB) *gorm.DB
- func (c *Criteria) BuildWithTxAndChangeTable(tx *gorm.DB) *gorm.DB
- func (c *Criteria) BuildWithTxIfPossible(tx *gorm.DB) *gorm.DB
- func (c *Criteria) BuildWithTxIfPossibleAndChangeTable(tx *gorm.DB) *gorm.DB
- func (c *Criteria) Desc(cols ...types.ColumnName) *Criteria
- func (c *Criteria) Eq(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) Exec(ctxt context.Context, sql *string, print bool) *gorm.DB
- func (c *Criteria) Ge(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) GeUTC(col types.ColumnName, ts int64) *Criteria
- func (c *Criteria) Gt(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) GtUTC(col types.ColumnName, ts int64) *Criteria
- func (c *Criteria) In(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) Is(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) Le(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) LeUTC(col types.ColumnName, ts int64) *Criteria
- func (c *Criteria) Like(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) Lt(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) LtUTC(col types.ColumnName, ts int64) *Criteria
- func (c *Criteria) Ne(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) Nin(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) NotNull(col types.ColumnName) *Criteria
- func (c *Criteria) Null(col types.ColumnName) *Criteria
- func (c *Criteria) Unlike(col types.ColumnName, arg any) *Criteria
- func (c *Criteria) Where() maps.Map[string, []any]
- type Database
- func (d *Database) Convert(s string, t types.ParameterType, tr *i18n.Localizer, log *slog.Logger) (v interface{}, err error)
- func (d *Database) DB() *gorm.DB
- func (d *Database) Escape(c types.ColumnName) string
- func (d *Database) EscapeCharacters() (string, string)
- func (d *Database) OptionalTx(ctx context.Context) *gorm.DB
- func (d *Database) Query(table ...string) *Criteria
- func (d *Database) Table(table string) *gorm.DB
- func (d *Database) TableWithContext(ctxt context.Context, table string) *gorm.DB
- func (d *Database) Tx(ctx context.Context, fc func(c context.Context, tx *gorm.DB) error, ...) (err error)
- type DatabaseProperties
- type NamingRule
- func (ns NamingRule) CheckerName(table, column string) string
- func (ns NamingRule) ColumnName(table, column string) (n string)
- func (ns NamingRule) IndexName(table, column string) string
- func (ns NamingRule) JoinTableName(str string) string
- func (ns NamingRule) RelationshipFKName(rel schema.Relationship) string
- func (ns NamingRule) SchemaName(table string) string
- func (ns NamingRule) TableName(str string) (n string)
- func (ns NamingRule) UniqueName(table, column string) string
Constants ¶
const ( At string = "@" Question string = "?" )
const IdentifierMaxLength = 64
Variables ¶
This section is empty.
Functions ¶
func DatabaseEscapeCharacters ¶
func DatabaseEscapeCharacters(typ types.DatabaseType) (string, string)
func RegistryDialectFactory ¶
func RegistryDialectFactory(t types.DatabaseType, factory func(DatabaseProperties) gorm.Dialector)
Types ¶
type Criteria ¶
type Criteria struct {
// contains filtered or unexported fields
}
func (*Criteria) BuildQuery ¶
func (*Criteria) BuildWithContext ¶
func (*Criteria) BuildWithTxAndChangeTable ¶
BuildWithTxAndChangeTable is a method that extends the functionality of the Criteria struct to support transactional operations across multiple tables. It takes a transactional database connection and changes the table context for the operation. This method is particularly useful when you need to perform actions that involve multiple tables within the scope of a single transaction. The function first builds the database connection with the given transaction using the BuildWithTx method. It then checks if the 'table' field in the Criteria struct is not nil. If 'table' is not nil, indicating that a specific table has been set, the method changes the table context to the one specified in the Criteria struct's 'table' field. If 'table' is nil, no table switching is performed, and the database connection remains in its original context.
Parameters:
tx *gorm.DB: The transactional database connection to use for the operation.
Returns:
*gorm.DB: The database connection, potentially with the table context changed if 'table' is not nil.
func (*Criteria) BuildWithTxIfPossible ¶
BuildWithTxIfPossible is a method that conditionally constructs a database query, either within the context of a transaction or as a regular DML operation. It checks if the provided transaction context (tx) is nil. If tx is nil, it indicates that there is no ongoing transaction, and the method will proceed with a non-transactional DML operation by calling the Build method. Otherwise, if tx is not nil, it implies that the operation should be part of an existing transaction, and the method will use the BuildWithTx method to continue within the transactional context.
Parameters:
tx *gorm.DB: The transactional database connection. If not nil, the query will be executed within a transaction.
Returns:
*gorm.DB: The constructed database query, either transactional or non-transactional.
func (*Criteria) BuildWithTxIfPossibleAndChangeTable ¶
BuildWithTxIfPossibleAndChangeTable checks if a transaction is provided and either continues within the transactional context using BuildWithTx or performs a non-transactional operation with Build. It also sets the table context if one is specified. See BuildWithTxIfPossible and BuildWithTxAndChangeTable for more details on transactional and table handling.
func (*Criteria) GeUTC ¶
func (c *Criteria) GeUTC(col types.ColumnName, ts int64) *Criteria
GeUTC adds a query criterion to filter rows where the specified column's UTC timestamp is greater or equal the given timestamp. The given timestamp is expected to be in milliseconds since the Unix epoch. This method is specifically designed for Oracle's TIMESTAMP type. It formats the timestamp into a string suitable for Oracle's TIMESTAMP format and appends the condition to the query criteria. The function returns the current Criteria instance for chaining.
func (*Criteria) GtUTC ¶
func (c *Criteria) GtUTC(col types.ColumnName, ts int64) *Criteria
GtUTC adds a query criterion to filter rows where the specified column's UTC timestamp is greater than the given timestamp. The given timestamp is expected to be in milliseconds since the Unix epoch. This method is specifically designed for Oracle's TIMESTAMP type. It formats the timestamp into a string suitable for Oracle's TIMESTAMP format and appends the condition to the query criteria. The function returns the current Criteria instance for chaining.
func (*Criteria) LeUTC ¶
func (c *Criteria) LeUTC(col types.ColumnName, ts int64) *Criteria
LeUTC adds a query criterion to filter rows where the specified column's UTC timestamp is less or equal the given timestamp. The given timestamp is expected to be in milliseconds since the Unix epoch. This method is specifically designed for Oracle's TIMESTAMP type. It formats the timestamp into a string suitable for Oracle's TIMESTAMP format and appends the condition to the query criteria. The function returns the current Criteria instance for chaining.
func (*Criteria) LtUTC ¶
func (c *Criteria) LtUTC(col types.ColumnName, ts int64) *Criteria
LtUTC adds a query criterion to filter rows where the specified column's UTC timestamp is less than the given timestamp. The given timestamp is expected to be in milliseconds since the Unix epoch. This method is specifically designed for Oracle's TIMESTAMP type. It formats the timestamp into a string suitable for Oracle's TIMESTAMP format and appends the condition to the query criteria. The function returns the current Criteria instance for chaining.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func New ¶
func New(properties DatabaseProperties) *Database
func (*Database) EscapeCharacters ¶
func (*Database) OptionalTx ¶
OptionalTx can be used to retrieve a gorm.DB pointer bound to given context.Context.
func (*Database) TableWithContext ¶
type DatabaseProperties ¶
type DatabaseProperties interface {
GetDSN() string
GetDialect() types.DatabaseType
GetDriver() string
GetMaxIdleConnections() int
GetMaxOpenConnections() int
GetMaxTableNameLength() int
GetConnMaxIdleTime() time.Duration
GetCreateBatchSize() int
GetLogLevel() int // see gorm.io/gorm/logger.LogLevel
ShouldPrepareStmt() bool
GetTablePrefix() string
GetSingularTable() bool
GetNameReplacer() schema.Replacer
GetNoLowerCase() bool
GetIdentifierMaxLength() int
Options() map[string]string
}
type NamingRule ¶
type NamingRule struct {
// contains filtered or unexported fields
}
func (NamingRule) CheckerName ¶
func (ns NamingRule) CheckerName(table, column string) string
func (NamingRule) ColumnName ¶
func (ns NamingRule) ColumnName(table, column string) (n string)
func (NamingRule) IndexName ¶
func (ns NamingRule) IndexName(table, column string) string
func (NamingRule) JoinTableName ¶
func (ns NamingRule) JoinTableName(str string) string
func (NamingRule) RelationshipFKName ¶
func (ns NamingRule) RelationshipFKName(rel schema.Relationship) string
func (NamingRule) SchemaName ¶
func (ns NamingRule) SchemaName(table string) string
func (NamingRule) TableName ¶
func (ns NamingRule) TableName(str string) (n string)
func (NamingRule) UniqueName ¶
func (ns NamingRule) UniqueName(table, column string) string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mysql contains mysql dialect factory.
|
Package mysql contains mysql dialect factory. |
|
Package oracle contains oracle dialect factory.
|
Package oracle contains oracle dialect factory. |
|
Package postgres contains postgres dialect factory.
|
Package postgres contains postgres dialect factory. |
|
Package sqlite contains sqlite dialect factory.
|
Package sqlite contains sqlite dialect factory. |
|
Package sqlserver contains sqlserver dialect factory.
|
Package sqlserver contains sqlserver dialect factory. |