Documentation
¶
Overview ¶
Package lssinglestore is a libschema.Driver for connecting to SingleStore databases.
Index ¶
- func Computed(name string, action func(context.Context, *sql.Tx) 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( name string, action func(context.Context, *sql.Tx) error, opts ...libschema.MigrationOption, ) libschema.Migration
Computed creates a libschema.Migration from a Go function to run the migration directly.
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