sqlite

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 21 Imported by: 25

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 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("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 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 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.

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 Diff added in v0.5.0

type Diff struct{}

A Diff provides a SQLite implementation for sqlx.DiffDriver.

func (*Diff) ColumnChange added in v0.5.0

func (d *Diff) ColumnChange(_ *schema.Table, from, to *schema.Column) (schema.ChangeKind, error)

ColumnChange returns the schema changes (if any) for migrating one column to the other.

func (*Diff) IndexAttrChanged added in v0.5.0

func (*Diff) IndexAttrChanged(from, to []schema.Attr) bool

IndexAttrChanged reports if the index attributes were changed.

func (*Diff) IndexPartAttrChanged added in v0.5.0

func (*Diff) IndexPartAttrChanged(_, _ *schema.IndexPart) bool

IndexPartAttrChanged reports if the index-part attributes were changed.

func (*Diff) IsGeneratedIndexName added in v0.5.0

func (d *Diff) IsGeneratedIndexName(t *schema.Table, idx *schema.Index) bool

IsGeneratedIndexName reports if the index name was generated by the database. See: https://github.com/sqlite/sqlite/blob/e937df8/src/build.c#L3583.

func (*Diff) Normalize added in v0.5.0

func (d *Diff) Normalize(from, to *schema.Table) error

Normalize implements the sqlx.Normalizer interface.

func (*Diff) ReferenceChanged added in v0.5.0

func (*Diff) ReferenceChanged(from, to schema.ReferenceOption) bool

ReferenceChanged reports if the foreign key referential action was changed.

func (*Diff) SchemaAttrDiff added in v0.5.0

func (d *Diff) SchemaAttrDiff(_, _ *schema.Schema) []schema.Change

SchemaAttrDiff returns a changeset for migrating schema attributes from one state to the other.

func (*Diff) TableAttrDiff added in v0.5.0

func (d *Diff) TableAttrDiff(from, to *schema.Table) ([]schema.Change, error)

TableAttrDiff returns a changeset for migrating table attributes from one state to the other.

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.

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