Documentation
¶
Index ¶
- Constants
- Variables
- type Array
- type CSVDB
- type Driver
- type MySQL
- func (m *MySQL) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
- func (m *MySQL) Close(db *sql.DB) error
- func (m *MySQL) Dialect() string
- func (m *MySQL) Open(dsn string) (*sql.DB, error)
- func (m *MySQL) Ping(ctx context.Context, db *sql.DB) error
- func (m *MySQL) Placeholder(n int) string
- type Oracle
- func (o *Oracle) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
- func (o *Oracle) Close(db *sql.DB) error
- func (o *Oracle) Dialect() string
- func (o *Oracle) Open(dsn string) (*sql.DB, error)
- func (o *Oracle) Ping(ctx context.Context, db *sql.DB) error
- func (o *Oracle) Placeholder(n int) string
- type PlaceholderFunc
- type PostgreSQL
- func (p *PostgreSQL) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
- func (p *PostgreSQL) Close(db *sql.DB) error
- func (p *PostgreSQL) Dialect() string
- func (p *PostgreSQL) Open(dsn string) (*sql.DB, error)
- func (p *PostgreSQL) Ping(ctx context.Context, db *sql.DB) error
- func (p *PostgreSQL) Placeholder(n int) string
- type SQLServer
- func (s *SQLServer) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
- func (s *SQLServer) Close(db *sql.DB) error
- func (s *SQLServer) Dialect() string
- func (s *SQLServer) Open(dsn string) (*sql.DB, error)
- func (s *SQLServer) Ping(ctx context.Context, db *sql.DB) error
- func (s *SQLServer) Placeholder(n int) string
- type SQLite
- func (s *SQLite) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
- func (s *SQLite) Close(db *sql.DB) error
- func (s *SQLite) Dialect() string
- func (s *SQLite) Open(dsn string) (*sql.DB, error)
- func (s *SQLite) Ping(ctx context.Context, db *sql.DB) error
- func (s *SQLite) Placeholder(n int) string
- type Turso
- func (t *Turso) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
- func (t *Turso) Close(db *sql.DB) error
- func (t *Turso) Dialect() string
- func (t *Turso) Open(dsn string) (*sql.DB, error)
- func (t *Turso) Ping(ctx context.Context, db *sql.DB) error
- func (t *Turso) Placeholder(n int) string
Constants ¶
const MaxArrayRows = 100000
MaxArrayRows limits the number of rows that can be populated in a single Populate call to prevent unbounded memory/CPU consumption.
const MaxCSVRows = 100000
MaxCSVRows limits the number of data rows that can be loaded from a single CSV file to prevent unbounded memory/CPU consumption. This mirrors the Array driver's MaxArrayRows limit.
Variables ¶
var PlaceholderFuncs = map[string]PlaceholderFunc{
"mysql": mysqlPlaceholder,
"oracle": oraclePlaceholder,
"postgres": postgresPlaceholder,
"sqlite": sqlitePlaceholder,
"sqlserver": sqlserverPlaceholder,
"turso": sqlitePlaceholder,
"array": sqlitePlaceholder,
}
PlaceholderFuncs contains placeholder functions for different dialects.
Functions ¶
This section is empty.
Types ¶
type Array ¶ added in v0.27.0
type Array struct {
*SQLite
// contains filtered or unexported fields
}
Array implements the Driver interface for array-backed storage using SQLite.
func (*Array) Cleanup ¶ added in v0.27.0
Cleanup removes all cached entries for the given *sql.DB from the populated and locks maps. This should be called when the connection is closed to prevent unbounded memory growth in long-running services.
func (*Array) Populate ¶ added in v0.27.0
func (a *Array) Populate(ctx context.Context, db *sql.DB, source contractsorm.ArraySource) error
Populate populates the database with rows from the given ArraySource.
type CSVDB ¶ added in v0.36.0
type CSVDB struct {
*SQLite
}
CSVDB implements the Driver interface for CSV-directory-backed storage. It embeds *SQLite for all standard Driver methods and overrides Open to scan a directory of CSV files and populate an in-memory SQLite database.
The directory path is passed as the DSN (from ConnectionConfig.Database). Each .csv file in the directory becomes a table named after the filename (without the .csv extension). The first row of each CSV is the header.
The driver is stateless — all state lives in the in-memory SQLite database.
func (*CSVDB) Dialect ¶ added in v0.36.0
Dialect returns "sqlite" so the query builder generates SQLite-compatible SQL and uses SQLite placeholders. The query builder's isSQLite() check returns true, and no ArraySource Model() hook fires (tables are already populated at Open time).
func (*CSVDB) Open ¶ added in v0.36.0
Open opens an in-memory SQLite database, scans the directory at dirPath for .csv files, and populates one table per file. The dirPath is the DSN, which comes from ConnectionConfig.Database via BuildDSN.
If dirPath is empty or ":memory:", no directory is scanned and an empty in-memory SQLite database is returned (useful for testing).
type Driver ¶
type Driver interface {
// Open opens a connection to the database.
Open(dsn string) (*sql.DB, error)
// Close closes the database connection.
Close(db *sql.DB) error
// Ping checks if the database connection is alive.
Ping(ctx context.Context, db *sql.DB) error
// BeginTx starts a transaction with the given options.
BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
// Placeholder returns the placeholder format for the driver.
Placeholder(n int) string
// Dialect returns the dialect name (mysql, postgres, sqlite, sqlserver, turso).
Dialect() string
}
Driver defines the interface for database driver implementations.
type MySQL ¶
type MySQL struct{}
MySQL implements the Driver interface for MySQL databases.
func (*MySQL) Placeholder ¶
Placeholder returns MySQL-style placeholders (?).
type Oracle ¶ added in v0.7.0
type Oracle struct{}
Oracle implements the Driver interface for Oracle databases.
func (*Oracle) BeginTx ¶ added in v0.7.0
BeginTx starts an Oracle transaction with the given options.
func (*Oracle) Placeholder ¶ added in v0.7.0
Placeholder returns Oracle-style placeholders (:1, :2, :3).
type PlaceholderFunc ¶
PlaceholderFunc is a function that generates placeholders for a given index.
func GetPlaceholderFunc ¶
func GetPlaceholderFunc(dialect string) PlaceholderFunc
GetPlaceholderFunc returns the placeholder function for the given dialect.
type PostgreSQL ¶
type PostgreSQL struct{}
PostgreSQL implements the Driver interface for PostgreSQL databases.
func NewPostgreSQL ¶
func NewPostgreSQL() *PostgreSQL
NewPostgreSQL creates a new PostgreSQL driver.
func (*PostgreSQL) Close ¶
func (p *PostgreSQL) Close(db *sql.DB) error
Close closes the PostgreSQL database connection.
func (*PostgreSQL) Dialect ¶
func (p *PostgreSQL) Dialect() string
Dialect returns the dialect name.
func (*PostgreSQL) Open ¶
func (p *PostgreSQL) Open(dsn string) (*sql.DB, error)
Open opens a connection to the PostgreSQL database.
func (*PostgreSQL) Placeholder ¶
func (p *PostgreSQL) Placeholder(n int) string
Placeholder returns PostgreSQL-style placeholders ($1, $2, $3).
type SQLServer ¶
type SQLServer struct{}
SQLServer implements the Driver interface for SQL Server databases.
func (*SQLServer) Placeholder ¶
Placeholder returns SQL Server-style placeholders (@p1, @p2, @p3).
type SQLite ¶
type SQLite struct{}
SQLite implements the Driver interface for SQLite databases.
func (*SQLite) Placeholder ¶
Placeholder returns SQLite-style placeholders (?).
type Turso ¶
type Turso struct{}
Turso implements the Driver interface for Turso databases.
func (*Turso) Placeholder ¶
Placeholder returns SQLite-style placeholders (?) since Turso uses SQLite.