orm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	At       string = "@"
	Question string = "?"
)
View Source
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 Query

func Query(db *Database, table ...string) *Criteria

func (*Criteria) Asc

func (c *Criteria) Asc(cols ...types.ColumnName) *Criteria

func (*Criteria) Between

func (c *Criteria) Between(col types.ColumnName, min, max any) *Criteria

func (*Criteria) Build

func (c *Criteria) Build() *gorm.DB

func (*Criteria) BuildQuery

func (c *Criteria) BuildQuery(sql *string) (statement string, args []any)

func (*Criteria) BuildWithContext

func (c *Criteria) BuildWithContext(ctx context.Context) *gorm.DB

func (*Criteria) BuildWithTx

func (c *Criteria) BuildWithTx(tx *gorm.DB) *gorm.DB

func (*Criteria) BuildWithTxAndChangeTable

func (c *Criteria) BuildWithTxAndChangeTable(tx *gorm.DB) *gorm.DB

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

func (c *Criteria) BuildWithTxIfPossible(tx *gorm.DB) *gorm.DB

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

func (c *Criteria) BuildWithTxIfPossibleAndChangeTable(tx *gorm.DB) *gorm.DB

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) Desc

func (c *Criteria) Desc(cols ...types.ColumnName) *Criteria

func (*Criteria) Eq

func (c *Criteria) Eq(col types.ColumnName, arg any) *Criteria

func (*Criteria) Exec

func (c *Criteria) Exec(ctxt context.Context, sql *string, print bool) *gorm.DB

func (*Criteria) Ge

func (c *Criteria) Ge(col types.ColumnName, arg any) *Criteria

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) Gt

func (c *Criteria) Gt(col types.ColumnName, arg any) *Criteria

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) In

func (c *Criteria) In(col types.ColumnName, arg any) *Criteria

func (*Criteria) Is

func (c *Criteria) Is(col types.ColumnName, arg any) *Criteria

func (*Criteria) Le

func (c *Criteria) Le(col types.ColumnName, arg any) *Criteria

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) Like

func (c *Criteria) Like(col types.ColumnName, arg any) *Criteria

func (*Criteria) Lt

func (c *Criteria) Lt(col types.ColumnName, arg any) *Criteria

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.

func (*Criteria) Ne

func (c *Criteria) Ne(col types.ColumnName, arg any) *Criteria

func (*Criteria) Nin

func (c *Criteria) Nin(col types.ColumnName, arg any) *Criteria

func (*Criteria) NotNull

func (c *Criteria) NotNull(col types.ColumnName) *Criteria

func (*Criteria) Null

func (c *Criteria) Null(col types.ColumnName) *Criteria

func (*Criteria) Unlike

func (c *Criteria) Unlike(col types.ColumnName, arg any) *Criteria

func (*Criteria) Where

func (c *Criteria) Where() maps.Map[string, []any]

type Database

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

func New

func New(properties DatabaseProperties) *Database

func (*Database) Convert

func (d *Database) Convert(s string, t types.ParameterType, tr *i18n.Localizer, log *slog.Logger) (v interface{}, err error)

func (*Database) DB

func (d *Database) DB() *gorm.DB

func (*Database) Escape

func (d *Database) Escape(c types.ColumnName) string

func (*Database) EscapeCharacters

func (d *Database) EscapeCharacters() (string, string)

func (*Database) OptionalTx

func (d *Database) OptionalTx(ctx context.Context) *gorm.DB

OptionalTx can be used to retrieve a gorm.DB pointer bound to given context.Context.

func (*Database) Query

func (d *Database) Query(table ...string) *Criteria

func (*Database) Table

func (d *Database) Table(table string) *gorm.DB

func (*Database) TableWithContext

func (d *Database) TableWithContext(ctxt context.Context, table string) *gorm.DB

func (*Database) Tx

func (d *Database) Tx(ctx context.Context, fc func(c context.Context, tx *gorm.DB) error, opts ...*sql.TxOptions) (err error)

Tx can be used to execute statement in an existing transaction, or in a newly created transaction.

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

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.

Jump to

Keyboard shortcuts

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