sqlite

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: Apache-2.0 Imports: 17 Imported by: 19

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

Variables

View Source
var (

	// UnmarshalHCL unmarshals an Atlas HCL DDL document into v.
	UnmarshalHCL = schemaspec.UnmarshalerFunc(func(data []byte, v interface{}) error {
		return evalSpec(data, v, nil)
	})
	// MarshalHCL marshals v into an Atlas HCL DDL document.
	MarshalHCL = schemaspec.MarshalerFunc(func(v interface{}) ([]byte, error) {
		return MarshalSpec(v, hclState)
	})
	// EvalHCL implements the schemahcl.Evaluator interface.
	EvalHCL = schemahcl.EvalFunc(evalSpec)
)
View Source
var TypeRegistry = schemahcl.NewRegistry(
	schemahcl.WithFormatter(FormatType),
	schemahcl.WithParser(ParseType),
	schemahcl.WithSpecs(
		schemahcl.TypeSpec(TypeReal, schemahcl.WithAttributes(&schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false})),
		schemahcl.TypeSpec(TypeBlob, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec(TypeText, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec(TypeInteger, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("int", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("tinyint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("smallint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("mediumint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("bigint", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.AliasTypeSpec("unsigned_big_int", "unsigned big int", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("int2", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("int8", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("double", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.AliasTypeSpec("double_precision", "double precision", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("float", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("character", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("varchar", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.AliasTypeSpec("varying_character", "varying character", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("nchar", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.AliasTypeSpec("native_character", "native character", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("nvarchar", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("clob", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.TypeSpec("numeric", schemahcl.WithAttributes(&schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false})),
		schemahcl.TypeSpec("decimal", schemahcl.WithAttributes(&schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false})),
		schemahcl.TypeSpec("boolean"),
		schemahcl.TypeSpec("date"),
		schemahcl.TypeSpec("datetime"),
		schemahcl.TypeSpec("json"),
		schemahcl.TypeSpec("uuid"),
	),
)

TypeRegistry contains the supported TypeSpecs for the sqlite driver.

Functions

func Build added in v0.1.0

func Build(phrase string) *sqlx.Builder

Build instantiates a new builder and writes the given phrase to it.

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 interface{}, marshaler schemaspec.Marshaler) ([]byte, error)

MarshalSpec marshals v into an Atlas DDL document using a schemaspec.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 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) Clean added in v0.3.8

func (d *Driver) Clean(ctx context.Context) error

Clean implements the inlined migrate.Clean interface to override the "emptying" behavior.

func (*Driver) IsClean added in v0.3.8

func (d *Driver) IsClean(ctx context.Context) (bool, error)

IsClean implements the inlined IsClean interface to override what to consider a clean 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 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

Jump to

Keyboard shortcuts

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