Documentation
¶
Index ¶
- func BuildDSN(config ConnectionConfig) (string, error)
- func QuoteIdentifier(identifier string, dialect string) string
- func QuoteValue(value any, dialect string) string
- type ColumnExpression
- type ConfigBuilder
- type ConnectionConfig
- type DBConfig
- func (c *DBConfig) Add(name string, configuration any)
- func (c *DBConfig) Env(envName string, defaultValue ...any) any
- func (c *DBConfig) Get(path string, defaultValue ...any) any
- func (c *DBConfig) GetBool(path string, defaultValue ...any) bool
- func (c *DBConfig) GetInt(path string, defaultValue ...any) int
- func (c *DBConfig) GetString(path string, defaultValue ...any) string
- type Expression
- type PoolConfig
- type RawExpression
- type ReplicaConfig
- type TableExpression
- type WhereExpression
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDSN ¶
func BuildDSN(config ConnectionConfig) (string, error)
BuildDSN builds a DSN string from a ConnectionConfig.
func QuoteIdentifier ¶
QuoteIdentifier quotes an identifier for SQL.
func QuoteValue ¶
QuoteValue quotes a value for SQL.
Types ¶
type ColumnExpression ¶
type ColumnExpression struct {
// contains filtered or unexported fields
}
ColumnExpression represents a column expression.
func NewColumnExpression ¶
func NewColumnExpression(column string) *ColumnExpression
NewColumnExpression creates a new column expression.
func (*ColumnExpression) String ¶
func (e *ColumnExpression) String() string
String returns the string representation of the column expression.
func (*ColumnExpression) Values ¶
func (e *ColumnExpression) Values() []any
Values returns the values for the column expression.
type ConfigBuilder ¶
type ConfigBuilder struct {
// contains filtered or unexported fields
}
ConfigBuilder builds DSN strings from connection configuration.
func NewConfigBuilder ¶
func NewConfigBuilder(config ConnectionConfig) *ConfigBuilder
NewConfigBuilder creates a new ConfigBuilder.
func (*ConfigBuilder) BuildDSN ¶
func (b *ConfigBuilder) BuildDSN() (string, error)
BuildDSN builds a DSN string from the connection configuration.
type ConnectionConfig ¶
type ConnectionConfig struct {
Driver string
Dsn string
Host string
Port int
Database string
Username string
Password string
Charset string
Schema string
SSLMode string
Loc string
Timezone string
Prefix string
Singular bool
NoLowerCase bool
NameReplacer any
Read []ReplicaConfig // read replicas; if non-empty, SELECTs are routed here
Write []ReplicaConfig // write primaries; if non-empty, mutating queries go here
}
ConnectionConfig represents a database connection configuration.
func ParseDSN ¶
func ParseDSN(dsn string) (ConnectionConfig, error)
ParseDSN parses a DSN string and extracts connection information.
func (ConnectionConfig) String ¶ added in v0.7.0
func (c ConnectionConfig) String() string
String returns a string representation of ConnectionConfig with password masked.
type DBConfig ¶
type DBConfig struct {
Default string
Connections map[string]ConnectionConfig
Pool PoolConfig
Debug bool
SlowThreshold int // slow query threshold in milliseconds (0 = disabled)
}
DBConfig represents the database configuration.
type Expression ¶
type Expression interface {
// String returns the string representation of the expression.
String() string
// Values returns the values for the expression.
Values() []any
}
Expression represents a database expression.
type PoolConfig ¶
type PoolConfig struct {
MaxIdleConns int
MaxOpenConns int
ConnMaxLifetime int // seconds
ConnMaxIdleTime int // seconds
QueryTimeout int // seconds (default: 30)
}
PoolConfig represents connection pool configuration.
type RawExpression ¶
type RawExpression struct {
// contains filtered or unexported fields
}
RawExpression represents a raw SQL expression.
func NewRawExpression ¶
func NewRawExpression(expr string, args ...any) *RawExpression
NewRawExpression creates a new raw expression.
func (*RawExpression) String ¶
func (e *RawExpression) String() string
String returns the string representation of the raw expression.
func (*RawExpression) Values ¶
func (e *RawExpression) Values() []any
Values returns the values for the raw expression.
type ReplicaConfig ¶ added in v0.2.0
ReplicaConfig holds host/port/credentials for a single read or write replica.
type TableExpression ¶
type TableExpression struct {
// contains filtered or unexported fields
}
TableExpression represents a table expression.
func NewTableExpression ¶
func NewTableExpression(table string, alias ...string) *TableExpression
NewTableExpression creates a new table expression.
func (*TableExpression) String ¶
func (e *TableExpression) String() string
String returns the string representation of the table expression.
func (*TableExpression) Values ¶
func (e *TableExpression) Values() []any
Values returns the values for the table expression.
type WhereExpression ¶
type WhereExpression struct {
// contains filtered or unexported fields
}
WhereExpression represents a where clause expression.
func NewWhereExpression ¶
func NewWhereExpression(column, operator string, value any, boolean ...string) *WhereExpression
NewWhereExpression creates a new where expression.
func (*WhereExpression) Boolean ¶
func (e *WhereExpression) Boolean() string
Boolean returns the boolean operator (AND/OR).
func (*WhereExpression) String ¶
func (e *WhereExpression) String() string
String returns the string representation of the where expression.
func (*WhereExpression) Values ¶
func (e *WhereExpression) Values() []any
Values returns the values for the where expression.