Documentation
¶
Overview ¶
Package lssinglestore is a libschema.Driver for connecting to SingleStore databases.
Index ¶
- func Computed[T lsmysql.ConnPtr](name string, action func(context.Context, T) error, ...) libschema.Migration
- func Generate(name string, generator func(context.Context, *sql.Tx) string, ...) libschema.Migration
- func Script(name string, sqlText string, opts ...libschema.MigrationOption) libschema.Migration
- type SingleStore
- func (p *SingleStore) CreateSchemaTableIfNotExists(ctx context.Context, _ *internal.Log, d *libschema.Database) error
- func (p *SingleStore) GetTableConstraint(table, constraintName string) (string, bool, error)
- func (p *SingleStore) LockMigrationsTable(ctx context.Context, _ *internal.Log, d *libschema.Database) error
- func (p *SingleStore) UnlockMigrationsTable(_ *internal.Log) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Computed ¶
func Computed[T lsmysql.ConnPtr]( name string, action func(context.Context, T) error, opts ...libschema.MigrationOption, ) libschema.Migration
Computed defines a migration that runs arbitrary Go code. The signature of the action callback determines if the migration runs transactionally or if it runs outside a transaction:
func(context.Context, *sql.Tx) error // run transactionlly func(context.Context, *sql.DB) error // run non-transactionally
func Generate ¶
func Generate(name string, generator func(context.Context, *sql.Tx) string, opts ...libschema.MigrationOption) libschema.Migration
Generate registers a callback that returns a migration in a string. To run the migration, libschema automatically chooses transactional (*sql.Tx) or non-transactional (*sql.DB) execution based on SingleStore rules for statements that cannot run inside a transaction (DML (insert/update) can be in a transaction but DDL (create table, etc) cannot be). If the migration will be run transactionally, it will run in the same transaction as the callback that returned the string. If it runs non-transactionally, the transaction that returned the string will be idle (hanging around) while the migration runs. The choice of transactional vs non-transactional Can be overridden with ForceNonTransactional() or ForceTransactional() options.
func Script ¶
Script defines a literal SQL statement migration. To run the migration, libschema automatically chooses transactional (*sql.Tx) or non-transactional (*sql.DB) execution based on SingleStore rules for statements that cannot run inside a transaction (DML (insert/update) can be in a transaction but DDL (create table, etc) cannot be). The choice of transactional vs non-transactional Can be overridden with ForceNonTransactional() or ForceTransactional() options.
Types ¶
type SingleStore ¶
SingleStore is a libschema.Driver for connecting to SingleStore databases.
Because SingleStore DDL commands cause transactions to autocommit, tracking the schema changes in a secondary table (like libschema does) is inherently unsafe. The SingleStore driver will record that it is about to attempt a migration and it will record if that attempts succeeds or fails, but if the program terminates mid-transaction, it is beyond the scope of libschema to determine if the transaction succeeded or failed. Such transactions will be retried. For this reason, it is reccomend that DDL commands be written such that they are idempotent.
There are methods the SingleStore type (inherited from lsmysql.MySQL) that can be used to query the state of the database and thus transform DDL commands that are not idempotent into idempotent commands by only running them if they need to be run.
Because Go's database/sql uses connection pooling and the SingleStore "USE database" command leaks out of transactions, it is strongly recommended that the libschema.Option value of SchemaOverride be set when creating the libschema.Schema object. That SchemaOverride will be propagated into the SingleStore object and be used as a default table for all of the functions to interrogate data defintion status.
func New ¶
func New(log *internal.Log, dbName string, schema *libschema.Schema, db *sql.DB) (*libschema.Database, *SingleStore, error)
New creates a libschema.Database with a Singlestore driver built in.
func (*SingleStore) CreateSchemaTableIfNotExists ¶
func (p *SingleStore) CreateSchemaTableIfNotExists(ctx context.Context, _ *internal.Log, d *libschema.Database) error
CreateSchemaTableIfNotExists creates the migration tracking table for libschema.
func (*SingleStore) GetTableConstraint ¶
func (p *SingleStore) GetTableConstraint(table, constraintName string) (string, bool, error)
GetTableConstraints returns the type of constraint and if it is enforced. The table is assumed to be in the current database unless m.UseDatabase() has been called.
func (*SingleStore) LockMigrationsTable ¶
func (p *SingleStore) LockMigrationsTable(ctx context.Context, _ *internal.Log, d *libschema.Database) error
LockMigrationsTable locks the migration tracking table for exclusive use by the migrations running now. It is expected to be called by libschema.
func (*SingleStore) UnlockMigrationsTable ¶
func (p *SingleStore) UnlockMigrationsTable(_ *internal.Log) error