Documentation
¶
Overview ¶
Package sqlmeta validates SQL Store tables and metadata on borrowed pools.
Index ¶
- func EnsureSQLTable(ctx context.Context, db *sqlx.DB, table SQLTable, statements ...string) error
- func ExternalSQLError(operation string, err error) error
- func LockPostgreSQLTable(ctx context.Context, tx *sqlx.Tx, table SQLTable) error
- func QuoteSQLIdentifier(dialect SQLDialect, value string) (string, error)
- func QuoteSQLTableName(dialect SQLDialect, value string) (string, error)
- func SQLColumns(ctx context.Context, db *sqlx.DB, backend SQLTable) (map[string]SQLColumn, error)
- func SQLIndexName(table SQLTable, purpose string) (string, error)
- func SQLUnixNano(value time.Time) (int64, error)
- func ValidateSQLColumns(got, want map[string]SQLColumn) error
- func ValidateSQLIdentifier(value string) error
- func ValidateSQLIndexColumns(ctx context.Context, db *sqlx.DB, backend SQLTable, name string, want []string) error
- func ValidateSQLSequenceIdentity(ctx context.Context, db *sqlx.DB, backend SQLTable, column string) error
- func ValidateSQLTableName(value string) error
- type SQLColumn
- type SQLDailyPartition
- type SQLDailyPartitions
- func (p SQLDailyPartitions) Check(ctx context.Context, db *sqlx.DB) error
- func (p SQLDailyPartitions) List(ctx context.Context, q sqlPartitionQueryer) ([]SQLDailyPartition, error)
- func (p SQLDailyPartitions) Maintain(ctx context.Context, tx *sqlx.Tx, cutoff time.Time, required []time.Time, ...) error
- func (p SQLDailyPartitions) Partition(at time.Time) (SQLDailyPartition, error)
- func (p SQLDailyPartitions) Prepare(ctx context.Context, tx *sqlx.Tx, required []time.Time) error
- type SQLDialect
- type SQLTable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureSQLTable ¶
EnsureSQLTable directly executes idempotent table/index initialization statements. It records no version or history and leaves the borrowed pool open.
PostgreSQL can reject concurrent CREATE ... IF NOT EXISTS statements for the same relation with catalog conflicts, so PostgreSQL statements run in one transaction serialized by LockPostgreSQLTable. SQLite executes them directly.
func ExternalSQLError ¶
ExternalSQLError preserves error identity while keeping driver text, which can contain bound values or connection details, out of the public error string. A driver SQLSTATE code carries no bound data and is kept for diagnosis.
func LockPostgreSQLTable ¶
LockPostgreSQLTable takes the transaction advisory lock that serializes DDL for one PostgreSQL table name in the current schema. Every Store kind uses the same key, so initialization and other DDL on that table cannot interleave.
func QuoteSQLIdentifier ¶
func QuoteSQLIdentifier(dialect SQLDialect, value string) (string, error)
QuoteSQLIdentifier returns a validated identifier quoted for SQLite or PostgreSQL.
func QuoteSQLTableName ¶
func QuoteSQLTableName(dialect SQLDialect, value string) (string, error)
QuoteSQLTableName returns a validated table name quoted for SQLite or PostgreSQL.
func SQLColumns ¶
SQLColumns returns the exact current-schema columns for a validated table.
func SQLIndexName ¶
SQLIndexName derives a stable, bounded identifier for one table index.
func SQLUnixNano ¶
SQLUnixNano returns a lossless signed nanosecond representation.
func ValidateSQLColumns ¶
ValidateSQLColumns requires the exact named column contract.
func ValidateSQLIdentifier ¶
ValidateSQLIdentifier validates an unqualified, portable SQL identifier.
func ValidateSQLIndexColumns ¶
func ValidateSQLIndexColumns(ctx context.Context, db *sqlx.DB, backend SQLTable, name string, want []string) error
ValidateSQLIndexColumns requires an exact, non-unique, non-partial index column order.
func ValidateSQLSequenceIdentity ¶
func ValidateSQLSequenceIdentity(ctx context.Context, db *sqlx.DB, backend SQLTable, column string) error
ValidateSQLSequenceIdentity requires the dialect-specific generated sequence contract used to break equal-timestamp Metrics ties.
func ValidateSQLTableName ¶
ValidateSQLTableName validates an unqualified SQL table name. KV prefixes may contain hyphens, which remain safe because every accepted name is quoted.
Types ¶
type SQLDailyPartition ¶
SQLDailyPartition is a managed UTC day with nanosecond range bounds.
type SQLDailyPartitions ¶
SQLDailyPartitions maintains day children of a PostgreSQL range parent. Prefix is owned by the caller so existing relation names remain stable.
func (SQLDailyPartitions) Check ¶
Check verifies the parent partition key and every attached managed child.
func (SQLDailyPartitions) List ¶
func (p SQLDailyPartitions) List(ctx context.Context, q sqlPartitionQueryer) ([]SQLDailyPartition, error)
List verifies attached child names and exact bounds before returning them.
func (SQLDailyPartitions) Maintain ¶
func (p SQLDailyPartitions) Maintain(ctx context.Context, tx *sqlx.Tx, cutoff time.Time, required []time.Time, beforeDrop func(SQLDailyPartition) error) error
Maintain runs under the parent's transaction advisory lock. Children wholly before cutoff are dropped; beforeDrop can clean caller-owned auxiliary rows in the same transaction. Required days and each following day are prepared.
func (SQLDailyPartitions) Partition ¶
func (p SQLDailyPartitions) Partition(at time.Time) (SQLDailyPartition, error)
Partition returns the managed child for the UTC day containing at.
type SQLDialect ¶
type SQLDialect string
SQLDialect identifies a supported SQL Store dialect.
const ( // SQLDialectSQLite is the modernc.org/sqlite dialect. SQLDialectSQLite SQLDialect = "sqlite" // SQLDialectPostgreSQL is the lib/pq dialect. SQLDialectPostgreSQL SQLDialect = "postgres" )
type SQLTable ¶
type SQLTable struct {
// contains filtered or unexported fields
}
SQLTable describes one validated logical table on a borrowed SQL pool.
func PrepareSQLTable ¶
PrepareSQLTable validates a borrowed pool, Store kind, and logical table.
func (SQLTable) Dialect ¶
func (table SQLTable) Dialect() SQLDialect
Dialect returns the table's validated SQL dialect.