Version: v0.10.1-0...-b753df1 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 22 Imported by: 12




View Source
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

View Source
const DriverName = "sqlite3"

DriverName holds the name used for registration.


View Source
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)
View Source
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.

View Source
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.

View Source
var TypeRegistry = schemahcl.NewRegistry(
		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})),

TypeRegistry contains the supported TypeSpecs for the sqlite driver.


func CommitFunc added in v0.7.2

func CommitFunc(ctx context.Context, db schema.ExecQuerier, tx Tx, on bool) (func() error, error)

CommitFunc takes a transaction and ensures to toggle foreign keys back on after tx.Commit is called.

func FormatType added in v0.2.0

func FormatType(t schema.Type) (string, error)

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

func MarshalSpec(v any, marshaler schemahcl.Marshaler) ([]byte, error)

MarshalSpec marshals v into an Atlas DDL document using a schemahcl.Marshaler.

func Open

Open opens a new SQLite driver.

func OpenTx added in v0.7.2

func OpenTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sqlclient.Tx, error)

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

func ParseType(c string) (schema.Type, error)

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

func RollbackFunc(ctx context.Context, db schema.ExecQuerier, tx Tx, on bool) func() error

RollbackFunc takes a transaction and ensures to toggle foreign keys back on after tx.Rollback is called.


type AutoIncrement added in v0.1.0

type AutoIncrement struct {
	// 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

type CreateStmt struct {
	S string

CreateStmt describes the SQL statement used to create a resource.

type Driver

type Driver struct {
	// 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

func (d *Driver) CheckClean(ctx context.Context, revT *migrate.TableIdent) error

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.

func (*Driver) Snapshot added in v0.5.0

func (d *Driver) Snapshot(ctx context.Context) (migrate.RestoreFunc, error)

Snapshot implements migrate.Snapshoter.

func (*Driver) Version added in v0.9.0

func (d *Driver) Version() string

Version returns the version of the connected database.

type File

type File struct {
	Name string

File describes a database file.

type IndexOrigin added in v0.1.0

type IndexOrigin struct {
	O string

IndexOrigin describes how the index was created. See: https://www.sqlite.org/pragma.html#pragma_index_list

type IndexPredicate

type IndexPredicate struct {
	P string

IndexPredicate describes a partial index predicate. See: https://www.sqlite.org/partialindex.html

type Tx added in v0.7.2

type Tx interface {
	Commit() error
	Rollback() error

Tx wraps schema.ExecQuerier with the transaction methods.

type UUIDType added in v0.1.0

type UUIDType struct {
	T string

A UUIDType defines a UUID type.

type WithoutRowID

type WithoutRowID struct {

WithoutRowID describes the `WITHOUT ROWID` configuration. See: https://sqlite.org/withoutrowid.html


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL