db

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

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

func QuoteIdentifier(identifier string, dialect string) string

QuoteIdentifier quotes an identifier for SQL.

func QuoteValue

func QuoteValue(value any, dialect string) string

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       contracts.Driver
	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
	Tables       any             // GODB: godb.Tables or []godb.Table; ignored by other drivers
	FS           fs.FS           // CSVDB/JSONDB/XMLDB: embedded filesystem (embed.FS / fs.FS); ignored by other drivers
}

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.

func (*ConnectionConfig) Validate added in v0.9.0

func (c *ConnectionConfig) Validate() error

Validate checks that the connection configuration has all required fields for the driver. If a DSN is provided directly, driver-specific field validation is skipped.

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.

func (*DBConfig) Add added in v0.2.0

func (c *DBConfig) Add(name string, configuration any)

Add implements config.Config interface for DBConfig (stub).

func (*DBConfig) Env added in v0.2.0

func (c *DBConfig) Env(envName string, defaultValue ...any) any

Env implements config.Config interface for DBConfig (stub).

func (*DBConfig) Get added in v0.2.0

func (c *DBConfig) Get(path string, defaultValue ...any) any

Get implements config.Config interface for DBConfig.

func (*DBConfig) GetBool added in v0.2.0

func (c *DBConfig) GetBool(path string, defaultValue ...any) bool

GetBool implements config.Config interface for DBConfig.

func (*DBConfig) GetInt added in v0.2.0

func (c *DBConfig) GetInt(path string, defaultValue ...any) int

GetInt implements config.Config interface for DBConfig.

func (*DBConfig) GetString added in v0.2.0

func (c *DBConfig) GetString(path string, defaultValue ...any) string

GetString implements config.Config interface for DBConfig.

func (*DBConfig) Validate added in v0.9.0

func (c *DBConfig) Validate() error

Validate checks that the database configuration has all required fields. It verifies that at least one connection is configured, the default connection exists, and each connection's driver-specific requirements are met.

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

type ReplicaConfig struct {
	Host     string
	Port     int
	Database string
	Username string
	Password string
}

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.

Jump to

Keyboard shortcuts

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