sqlite

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: Apache-2.0 Imports: 15 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

Variables

View Source
var (

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

func UnmarshalSpec(data []byte, unmarshaler schemaspec.Unmarshaler, v interface{}) error

UnmarshalSpec unmarshals an Atlas DDL document using an unmarshaler into v.

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 Open

func Open(db schema.ExecQuerier) (*Driver, error)

Open opens a new SQLite driver.

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