Documentation ¶
Index ¶
- Constants
- Variables
- func CommitFunc(ctx context.Context, db schema.ExecQuerier, tx Tx, on bool) (func() error, error)
- func FormatType(t schema.Type) (string, error)
- func MarshalSpec(v any, marshaler schemahcl.Marshaler) ([]byte, error)
- func Open(db schema.ExecQuerier) (migrate.Driver, error)
- func OpenTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sqlclient.Tx, error)
- func ParseType(c string) (schema.Type, error)
- func RollbackFunc(ctx context.Context, db schema.ExecQuerier, tx Tx, on bool) func() error
- type AutoIncrement
- type CreateStmt
- type Driver
- type File
- type IndexOrigin
- type IndexPredicate
- type Tx
- type UUIDType
- type WithoutRowID
Constants ¶
const ( TypeInteger = "integer" // SQLITE_TYPE_INTEGER TypeReal = "real" // SQLITE_TYPE_REAL TypeText = "text" // SQLITE_TYPE_TEXT TypeBlob = "blob" // SQLITE_TYPE_BLOB )
SQLite standard data types as defined in its codebase and documentation. https://www.sqlite.org/datatype3.html https://github.com/sqlite/sqlite/blob/master/src/global.c
const DriverName = "sqlite3"
DriverName holds the name used for registration.
Variables ¶
var ( // MarshalHCL marshals v into an Atlas HCL DDL document. MarshalHCL = schemahcl.MarshalerFunc(func(v any) ([]byte, error) { return MarshalSpec(v, hclState) }) // EvalHCL implements the schemahcl.Evaluator interface. EvalHCL = schemahcl.EvalFunc(evalSpec) // EvalHCLBytes is a helper that evaluates an HCL document from a byte slice instead // of from an hclparse.Parser instance. EvalHCLBytes = specutil.HCLBytesFunc(EvalHCL) )
var DefaultDiff schema.Differ = &sqlx.Diff{DiffDriver: &diff{}}
DefaultDiff provides basic diffing capabilities for MySQL dialects. Note, it is recommended to call Open, create a new Driver and use its Differ when a database connection is available.
var DefaultPlan migrate.PlanApplier = &planApply{conn: conn{ExecQuerier: sqlx.NoRows}}
DefaultPlan provides basic planning capabilities for SQLite dialects. Note, it is recommended to call Open, create a new Driver and use its migrate.PlanApplier when a database connection is available.
var TypeRegistry = schemahcl.NewRegistry( schemahcl.WithFormatter(FormatType), schemahcl.WithParser(ParseType), schemahcl.WithSpecs( schemahcl.NewTypeSpec(TypeReal, schemahcl.WithAttributes(&schemahcl.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemahcl.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false})), schemahcl.NewTypeSpec(TypeBlob, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeText, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeInteger, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("int", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("tinyint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("smallint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("mediumint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("bigint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.AliasTypeSpec("unsigned_big_int", "unsigned big int", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("int2", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("int8", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("uint64", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("double", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.AliasTypeSpec("double_precision", "double precision", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("float", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("character", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("varchar", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.AliasTypeSpec("varying_character", "varying character", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("nchar", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.AliasTypeSpec("native_character", "native character", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("nvarchar", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("clob", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec("numeric", schemahcl.WithAttributes(&schemahcl.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemahcl.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false})), schemahcl.NewTypeSpec("decimal", schemahcl.WithAttributes(&schemahcl.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemahcl.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false})), schemahcl.NewTypeSpec("bool"), schemahcl.NewTypeSpec("boolean"), schemahcl.NewTypeSpec("date"), schemahcl.NewTypeSpec("datetime"), schemahcl.NewTypeSpec("json"), schemahcl.NewTypeSpec("uuid"), ), )
TypeRegistry contains the supported TypeSpecs for the sqlite driver.
Functions ¶
func CommitFunc ¶ added in v0.7.2
CommitFunc takes a transaction and ensures to toggle foreign keys back on after tx.Commit is called.
func FormatType ¶ added in v0.2.0
FormatType converts types to one format. A lowered format. This is due to SQLite flexibility to allow any data types and use a set of rules to define the type affinity. See: https://www.sqlite.org/datatype3.html
func MarshalSpec ¶
MarshalSpec marshals v into an Atlas DDL document using a schemahcl.Marshaler.
func Open ¶
func Open(db schema.ExecQuerier) (migrate.Driver, error)
Open opens a new SQLite driver.
func OpenTx ¶ added in v0.7.2
OpenTx opens a transaction. If foreign keys are enabled, it disables them, checks for constraint violations, opens the transaction and before committing ensures no new violations have been introduced by whatever Atlas was doing.
func ParseType ¶ added in v0.3.0
ParseType returns the schema.Type value represented by the given raw type. It is expected to be one of the types in https://www.sqlite.org/datatypes.html, or some of the common types used by ORMs like Ent.
func RollbackFunc ¶ added in v0.7.2
RollbackFunc takes a transaction and ensures to toggle foreign keys back on after tx.Rollback is called.
Types ¶
type AutoIncrement ¶ added in v0.1.0
type AutoIncrement struct { schema.Attr // Seq represents the value in sqlite_sequence table. // i.e. https://www.sqlite.org/fileformat2.html#seqtab. // // Setting this value manually to > 0 indicates that // a custom value is necessary and should be handled // on migrate. Seq int64 }
AutoIncrement describes the `AUTOINCREMENT` configuration. https://www.sqlite.org/autoinc.html
type CreateStmt ¶
CreateStmt describes the SQL statement used to create a resource.
type Driver ¶
type Driver struct { schema.Differ schema.Inspector migrate.PlanApplier // contains filtered or unexported fields }
Driver represents a SQLite driver for introspecting database schemas, generating diff between schema elements and apply migrations changes.
func (*Driver) CheckClean ¶ added in v0.6.0
CheckClean implements migrate.CleanChecker.
func (*Driver) Lock ¶ added in v0.4.1
func (d *Driver) Lock(_ context.Context, name string, timeout time.Duration) (schema.UnlockFunc, error)
Lock implements the schema.Locker interface.
type IndexOrigin ¶ added in v0.1.0
IndexOrigin describes how the index was created. See: https://www.sqlite.org/pragma.html#pragma_index_list
type IndexPredicate ¶
IndexPredicate describes a partial index predicate. See: https://www.sqlite.org/partialindex.html
type Tx ¶ added in v0.7.2
type Tx interface { schema.ExecQuerier Commit() error Rollback() error }
Tx wraps schema.ExecQuerier with the transaction methods.
type WithoutRowID ¶
WithoutRowID describes the `WITHOUT ROWID` configuration. See: https://sqlite.org/withoutrowid.html