Documentation
¶
Index ¶
- Constants
- Variables
- type Array
- type Aztables
- func (a *Aztables) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
- func (a *Aztables) Close(db *sql.DB) error
- func (a *Aztables) Dialect() string
- func (a *Aztables) Open(dsn string) (*sql.DB, error)
- func (a *Aztables) Ping(ctx context.Context, db *sql.DB) error
- func (a *Aztables) Placeholder(n int) string
- type CSVDB
- type Driver
- type GODB
- type JSONDB
- 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 Table
- type Tables
- 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
- type XMLDB
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.
const MaxGODBRows = 100000
MaxGODBRows limits the number of rows that can be populated in a single table.
Variables ¶
var PlaceholderFuncs = map[string]PlaceholderFunc{
"mysql": mysqlPlaceholder,
"oracle": oraclePlaceholder,
"postgres": postgresPlaceholder,
"sqlite": sqlitePlaceholder,
"sqlserver": sqlserverPlaceholder,
"turso": sqlitePlaceholder,
"array": sqlitePlaceholder,
"aztables": 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 Aztables ¶ added in v0.43.0
type Aztables struct{}
Aztables implements the Driver interface for Azure Table Storage via the aztablessql database/sql driver (github.com/dracory/aztablessql).
The DSN is an Azure Storage connection string, e.g.
"DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...;EndpointSuffix=core.windows.net"
For local development with Azurite, use the well-known dev-store connection string pointing at the Azurite Table endpoint.
Table Storage has no cross-partition transactions; BeginTx will fail with the aztablessql driver's "transactions not supported" error. Use the aztablessql batch API (Conn.Raw) for atomic multi-entity writes within a single partition.
func NewAztables ¶ added in v0.43.0
func NewAztables() *Aztables
NewAztables creates a new Aztables driver.
func (*Aztables) BeginTx ¶ added in v0.43.0
BeginTx starts a transaction. Azure Table Storage does not support cross-partition transactions, so this returns the aztablessql driver's "transactions not supported" error. Use the batch API for atomic single-partition writes.
func (*Aztables) Open ¶ added in v0.43.0
Open opens a connection to Azure Table Storage via the aztablessql driver.
func (*Aztables) Ping ¶ added in v0.43.0
Ping checks if the Azure Table Storage connection is alive.
func (*Aztables) Placeholder ¶ added in v0.43.0
Placeholder returns Azure Table Storage-style placeholders (?). The aztablessql driver uses ? placeholders, same as SQLite/MySQL.
type CSVDB ¶ added in v0.36.0
type CSVDB struct {
*SQLite
// contains filtered or unexported fields
}
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 GODB ¶ added in v0.39.0
type GODB struct {
*SQLite
// contains filtered or unexported fields
}
GODB implements the Driver interface for Go-data-backed storage. It embeds *SQLite for all standard Driver methods and overrides Open to populate an in-memory SQLite database from Go data slices passed via the config Tables field.
The data is compiled into the binary at build time by the Go compiler. At runtime, the driver converts each data slice to rows and inserts them into SQLite. No file I/O, no parsing.
func (*GODB) Dialect ¶ added in v0.39.0
Dialect returns "sqlite" so the query builder generates SQLite-compatible SQL and uses SQLite placeholders.
type JSONDB ¶ added in v0.37.0
type JSONDB struct {
*SQLite
// contains filtered or unexported fields
}
JSONDB implements the Driver interface for JSON-directory-backed storage. It embeds *SQLite for all standard Driver methods and overrides Open to scan a directory of JSON, JSONL, or NDJSON files and populate an in-memory SQLite database.
The directory path is passed as the DSN (from ConnectionConfig.Database). Each .json, .jsonl, or .ndjson file becomes a table named after the filename (without the extension). Object keys define the columns.
The driver is stateless — all state lives in the in-memory SQLite database.
func (*JSONDB) Dialect ¶ added in v0.37.0
Dialect returns "sqlite" so the query builder generates SQLite-compatible SQL and uses SQLite placeholders.
func (*JSONDB) Open ¶ added in v0.37.0
Open opens an in-memory SQLite database, scans the directory at dirPath for .json, .jsonl, and .ndjson 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 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 Table ¶ added in v0.39.0
Table is an alternative config style that preserves declaration order. Useful if table creation order matters (e.g., for foreign key constraints).
Usage in config:
Tables: []godb.Table{
{Name: "blogs", Data: blogs.Blogs},
{Name: "categories", Data: blogs.Categories},
}
type Tables ¶ added in v0.39.0
Tables is a map of table names to data slices. Each value can be []map[string]any, []SomeStruct, or any slice.
Usage in config:
Tables: godb.Tables{
"blogs": blogs.Blogs,
"categories": blogs.Categories,
}
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.
type XMLDB ¶ added in v0.37.0
type XMLDB struct {
*SQLite
// contains filtered or unexported fields
}
XMLDB implements the Driver interface for XML-directory-backed storage. It embeds *SQLite for all standard Driver methods and overrides Open to scan a directory of XML files and populate an in-memory SQLite database.
The directory path is passed as the DSN (from ConnectionConfig.Database). Each .xml file in the directory becomes a table named after the filename (without the .xml extension). The root element is the container; each direct child element is a row. Attributes and leaf sub-elements define the columns.
The driver is stateless — all state lives in the in-memory SQLite database.
func (*XMLDB) Dialect ¶ added in v0.37.0
Dialect returns "sqlite" so the query builder generates SQLite-compatible SQL and uses SQLite placeholders.
func (*XMLDB) Open ¶ added in v0.37.0
Open opens an in-memory SQLite database, scans the directory at dirPath for .xml 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).