sqlite

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 21 Imported by: 22

Documentation

Index

Constants

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.

Variables

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.WithFormatter(FormatType),
	schemahcl.WithParser(ParseType),
	schemahcl.WithSpecs(
		schemahcl.NewTypeSpec(TypeReal, schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		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.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		schemahcl.NewTypeSpec("decimal", schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		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

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.

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

type CreateStmt struct {
	schema.Attr
	S string
}

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

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 {
	schema.Attr
	Name string
}

File describes a database file.

type IndexOrigin added in v0.1.0

type IndexOrigin struct {
	schema.Attr
	O string
}

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

type IndexPredicate

type IndexPredicate struct {
	schema.Attr
	P string
}

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

type Strict added in v0.12.1

type Strict struct {
	schema.Attr
}

Strict describes the `STRICT` configuration. See: https://sqlite.org/stricttables.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 UUIDType added in v0.1.0

type UUIDType struct {
	schema.Type
	T string
}

A UUIDType defines a UUID type.

type WithoutRowID

type WithoutRowID struct {
	schema.Attr
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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