sqlite

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 28 Imported by: 3

Documentation

Index

Constants

View Source
const CommentPreventingIndexBuilding = "__FOR TESTING: I cannot be built__"
View Source
const IndexDriverId = "SqliteIndexDriver"

Variables

View Source
var (
	FieldNoExist error = errors.New("field no exist")
)

Functions

func EncodeIndexValue

func EncodeIndexValue(value *IndexValue) ([]byte, error)

func GetInsertSql added in v0.1.16

func GetInsertSql(value sql.Row, schema sql.Schema, tableName string) error

func InitDB

func InitDB() orm.DBconnect

func NewSqliteDBProvider

func NewSqliteDBProvider(dbs ...sql.Database) sql.MutableDatabaseProvider

func NewTableEditAccumulator

func NewTableEditAccumulator(t *Table) tableEditAccumulator

NewTableEditAccumulator returns a tableEditAccumulator based on the schema.

func Strval

func Strval(value interface{}) string

Strval 获取变量的字符串值 浮点型 3.0将会转换成字符串3, "3" 非数值或字符类型的变量将会被转换成JSON格式字符串

Types

type BaseDatabase

type BaseDatabase struct {
	// contains filtered or unexported fields
}

BaseDatabase is an in-sqlite database that can't store views, only for testing the engine

func NewViewlessDatabase

func NewViewlessDatabase(name string) *BaseDatabase

NewViewlessDatabase creates a new database that doesn't persist views. Used only for testing. Use NewDatabase.

func (*BaseDatabase) AddTable

func (d *BaseDatabase) AddTable(name string, t sql.Table)

AddTable adds a new table to the database.

func (*BaseDatabase) Address

func (d *BaseDatabase) Address() string

func (*BaseDatabase) Connection

func (d *BaseDatabase) Connection() *dbsql.DB

Connection returns the database connection.

func (*BaseDatabase) CreateTable

func (d *BaseDatabase) CreateTable(ctx *sql.Context, name string, schema sql.PrimaryKeySchema) error

CreateTable creates a table with the given name and schema

func (*BaseDatabase) CreateTrigger

func (d *BaseDatabase) CreateTrigger(ctx *sql.Context, definition sql.TriggerDefinition) error

func (*BaseDatabase) DropStoredProcedure

func (d *BaseDatabase) DropStoredProcedure(ctx *sql.Context, name string) error

DropStoredProcedure implements sql.StoredProcedureDatabase

func (*BaseDatabase) DropTable

func (d *BaseDatabase) DropTable(ctx *sql.Context, name string) error

DropTable drops the table with the given name

func (*BaseDatabase) DropTrigger

func (d *BaseDatabase) DropTrigger(ctx *sql.Context, name string) error

func (*BaseDatabase) EnablePrimaryKeyIndexes

func (d *BaseDatabase) EnablePrimaryKeyIndexes()

EnablePrimaryKeyIndexes causes every table created in this database to use an index on its primary partitionKeys

func (*BaseDatabase) GetStoredProcedures

func (d *BaseDatabase) GetStoredProcedures(ctx *sql.Context) ([]sql.StoredProcedureDetails, error)

GetStoredProcedures implements sql.StoredProcedureDatabase

func (*BaseDatabase) GetTableInsensitive

func (d *BaseDatabase) GetTableInsensitive(ctx *sql.Context, tblName string) (sql.Table, bool, error)

func (*BaseDatabase) GetTableNames

func (d *BaseDatabase) GetTableNames(ctx *sql.Context) ([]string, error)

func (*BaseDatabase) GetTableNamesBak

func (d *BaseDatabase) GetTableNamesBak(ctx *sql.Context) ([]string, error)

func (*BaseDatabase) GetTableSchema

func (d *BaseDatabase) GetTableSchema(name string) (sql.PrimaryKeySchema, error)

func (*BaseDatabase) GetTriggers

func (d *BaseDatabase) GetTriggers(ctx *sql.Context) ([]sql.TriggerDefinition, error)

func (*BaseDatabase) InitTables

func (d *BaseDatabase) InitTables()

Tables returns all tables in the database.

func (*BaseDatabase) Name

func (d *BaseDatabase) Name() string

Name returns the database name.

func (*BaseDatabase) ParseColumnStringToSqlType

func (d *BaseDatabase) ParseColumnStringToSqlType(atype string) (sql.Type, error)

func (*BaseDatabase) RenameTable

func (d *BaseDatabase) RenameTable(ctx *sql.Context, oldName, newName string) error

func (*BaseDatabase) SaveStoredProcedure

func (d *BaseDatabase) SaveStoredProcedure(ctx *sql.Context, spd sql.StoredProcedureDetails) error

SaveStoredProcedure implements sql.StoredProcedureDatabase

func (*BaseDatabase) Tables

func (d *BaseDatabase) Tables() map[string]sql.Table

Tables returns all tables in the database.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewSchemeBuilder

func NewSchemeBuilder() *Builder

func (*Builder) AddBool

func (b *Builder) AddBool(name string) *Builder

func (*Builder) AddField

func (b *Builder) AddField(field string, typ reflect.Type) *Builder

添加字段

func (*Builder) AddFloat64

func (b *Builder) AddFloat64(name string) *Builder

func (*Builder) AddInt64

func (b *Builder) AddInt64(name string) *Builder

func (*Builder) AddString

func (b *Builder) AddString(name string) *Builder

func (*Builder) Build

func (b *Builder) Build() *Struct

根据预先添加的字段构建出结构体

type Database

type Database struct {
	*BaseDatabase
	// contains filtered or unexported fields
}

Database is an in-sqlite database.

func NewDatabase

func NewDatabase(name string) *Database

NewDatabase creates a new database with the given name.

func (*Database) AllViews

func (d *Database) AllViews(ctx *sql.Context) ([]sql.ViewDefinition, error)

func (*Database) CreateView

func (d *Database) CreateView(ctx *sql.Context, name string, selectStatement string) error

func (*Database) DropView

func (d *Database) DropView(ctx *sql.Context, name string) error

func (*Database) GetView

func (d *Database) GetView(ctx *sql.Context, viewName string) (string, bool, error)

type ExpressionsIndex

type ExpressionsIndex interface {
	sql.Index
	MemTable() *Table
	ColumnExpressions() []sql.Expression
}

ExpressionsIndex is an index made out of one or more expressions (usually field expressions), linked to a Table.

type FilteredTable

type FilteredTable struct {
	*Table
}

sql.FilteredTable functionality in the Table type was disabled for a long period of time, and has developed major issues with the current analyzer logic. It's only used in the pushdown unit tests, and sql.FilteredTable should be considered unstable until this situation is fixed.

func NewFilteredTable

func NewFilteredTable(name string, schema sql.PrimaryKeySchema) *FilteredTable

func (*FilteredTable) WithFilters

func (t *FilteredTable) WithFilters(ctx *sql.Context, filters []sql.Expression) sql.Table

WithFilters implements the sql.FilteredTable interface.

func (*FilteredTable) WithProjection

func (t *FilteredTable) WithProjection(colNames []string) sql.Table

WithFilters implements the sql.FilteredTable interface.

type GlobalsMap

type GlobalsMap = map[string]interface{}

type HistoryDatabase

type HistoryDatabase struct {
	*Database
	Revisions map[string]map[interface{}]sql.Table
	// contains filtered or unexported fields
}

HistoryDatabase is a test-only VersionedDatabase implementation. It only supports exact lookups, not AS OF queries between two revisions. It's constructed just like its non-versioned sibling, but it can receive updates to particular tables via the AddTableAsOf method. Consecutive calls to AddTableAsOf with the same table must install new versions of the named table each time, with ascending version identifiers, for this to work.

func NewHistoryDatabase

func NewHistoryDatabase(name string) *HistoryDatabase

func (*HistoryDatabase) AddTableAsOf

func (db *HistoryDatabase) AddTableAsOf(name string, t sql.Table, asOf interface{})

Adds a table with an asOf revision key. The table given becomes the current version for the name given.

func (*HistoryDatabase) GetTableInsensitiveAsOf

func (db *HistoryDatabase) GetTableInsensitiveAsOf(ctx *sql.Context, tblName string, time interface{}) (sql.Table, bool, error)

func (*HistoryDatabase) GetTableNamesAsOf

func (db *HistoryDatabase) GetTableNamesAsOf(ctx *sql.Context, time interface{}) ([]string, error)

type InSqlitePersistedSession

type InSqlitePersistedSession struct {
	sql.Session
	// contains filtered or unexported fields
}

func NewInSqlitePersistedSession

func NewInSqlitePersistedSession(sess sql.Session, persistedGlobals GlobalsMap) *InSqlitePersistedSession

NewInSqlitePersistedSession is a sql.PersistableSession that writes global variables to an im-memory map

func (*InSqlitePersistedSession) GetPersistedValue

func (s *InSqlitePersistedSession) GetPersistedValue(k string) (interface{}, error)

RemoveAllPersistedGlobals implements sql.PersistableSession

func (*InSqlitePersistedSession) PersistGlobal

func (s *InSqlitePersistedSession) PersistGlobal(sysVarName string, value interface{}) error

PersistGlobal implements sql.PersistableSession

func (*InSqlitePersistedSession) RemoveAllPersistedGlobals

func (s *InSqlitePersistedSession) RemoveAllPersistedGlobals() error

RemoveAllPersistedGlobals implements sql.PersistableSession

func (*InSqlitePersistedSession) RemovePersistedGlobal

func (s *InSqlitePersistedSession) RemovePersistedGlobal(sysVarName string) error

RemovePersistedGlobal implements sql.PersistableSession

type Index

type Index struct {
	DB         string // required for engine tests with driver
	DriverName string // required for engine tests with driver
	Tbl        *Table // required for engine tests with driver
	TableName  string
	Exprs      []sql.Expression
	Name       string
	Unique     bool
	CommentStr string
}

func (*Index) ColumnExpressionTypes

func (idx *Index) ColumnExpressionTypes(*sql.Context) []sql.ColumnExpressionType

ColumnExpressionTypes implements the interface sql.Index.

func (*Index) ColumnExpressions

func (idx *Index) ColumnExpressions() []sql.Expression

func (*Index) Comment

func (idx *Index) Comment() string

func (*Index) Database

func (idx *Index) Database() string

func (*Index) Driver

func (idx *Index) Driver() string

func (*Index) Expressions

func (idx *Index) Expressions() []string

func (*Index) ID

func (idx *Index) ID() string

func (*Index) IndexType

func (idx *Index) IndexType() string

func (*Index) IsGenerated

func (idx *Index) IsGenerated() bool

func (*Index) IsUnique

func (idx *Index) IsUnique() bool

func (*Index) MemTable

func (idx *Index) MemTable() *Table

func (*Index) NewLookup

func (idx *Index) NewLookup(ctx *sql.Context, ranges ...sql.Range) (sql.IndexLookup, error)

NewLookup implements the interface sql.Index.

func (*Index) Table

func (idx *Index) Table() string

type IndexLookup

type IndexLookup struct {
	Expr sql.Expression
	// contains filtered or unexported fields
}

func NewIndexLookup

func NewIndexLookup(ctx *sql.Context, idx ExpressionsIndex, expr sql.Expression, ranges ...sql.Range) *IndexLookup

func (*IndexLookup) EvalExpression

func (eil *IndexLookup) EvalExpression() sql.Expression

func (*IndexLookup) Index

func (eil *IndexLookup) Index() sql.Index

Index implements the interface sql.IndexLookup.

func (*IndexLookup) Indexes

func (eil *IndexLookup) Indexes() []string

func (*IndexLookup) Ranges

func (eil *IndexLookup) Ranges() sql.RangeCollection

Ranges implements the interface sql.IndexLookup.

func (*IndexLookup) String

func (eil *IndexLookup) String() string

func (*IndexLookup) Values

func (eil *IndexLookup) Values(p sql.Partition) (sql.IndexValueIter, error)

type IndexValue

type IndexValue struct {
	Key string
	Pos int
}

func DecodeIndexValue

func DecodeIndexValue(data []byte) (*IndexValue, error)

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

结构体的值

func (*Instance) Addr

func (i *Instance) Addr() interface{}

func (Instance) Field

func (in Instance) Field(name string) (reflect.Value, error)

func (*Instance) Interface

func (i *Instance) Interface() interface{}

type ParseColumn

type ParseColumn struct {
	Cid        int8
	Name       string
	Type       sql.Type
	Notnull    string
	Dflt_value string
	Pk         string
}

type Partition

type Partition struct {
	// contains filtered or unexported fields
}

func NewPartition

func NewPartition(key []byte) *Partition

func (*Partition) Key

func (p *Partition) Key() []byte

type ReadOnlyDatabase

type ReadOnlyDatabase struct {
	*HistoryDatabase
}

func NewReadOnlyDatabase

func NewReadOnlyDatabase(name string) ReadOnlyDatabase

func (ReadOnlyDatabase) IsReadOnly

func (d ReadOnlyDatabase) IsReadOnly() bool

type SqliteDatabase

type SqliteDatabase interface {
	sql.Database
	AddTable(name string, t sql.Table)
}

type Struct

type Struct struct {
	// contains filtered or unexported fields
}

结构体的类型

func (Struct) New

func (s Struct) New() *Instance

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table represents an in-memory database table.

func NewPartitionedTable

func NewPartitionedTable(name string, schema sql.PrimaryKeySchema, numPartitions int) *Table

NewPartitionedTable creates a new Table with the given name, schema and number of partitions.

func NewTable

func NewTable(name string, schema sql.PrimaryKeySchema) *Table

NewTable creates a new Table with the given name and schema.

func (*Table) AddColumn

func (t *Table) AddColumn(ctx *sql.Context, column *sql.Column, order *sql.ColumnOrder) error

func (*Table) ApplyEdits

func (t *Table) ApplyEdits(ctx *sql.Context) error

func (*Table) AutoIncrementSetter

func (t *Table) AutoIncrementSetter(ctx *sql.Context) sql.AutoIncrementSetter

func (*Table) CreateCheck

func (t *Table) CreateCheck(_ *sql.Context, check *sql.CheckDefinition) error

CreateCheck implements sql.CheckAlterableTable

func (*Table) CreateForeignKey

func (t *Table) CreateForeignKey(_ *sql.Context, fkName string, columns []string, referencedTable string, referencedColumns []string, onUpdate, onDelete sql.ForeignKeyReferenceOption) error

CreateForeignKey implements sql.ForeignKeyAlterableTable. Foreign partitionKeys are not enforced on update / delete.

func (*Table) CreateIndex

func (t *Table) CreateIndex(ctx *sql.Context, indexName string, using sql.IndexUsing, constraint sql.IndexConstraint, columns []sql.IndexColumn, comment string) error

CreateIndex implements sql.IndexAlterableTable

func (*Table) CreatePrimaryKey

func (t *Table) CreatePrimaryKey(ctx *sql.Context, columns []sql.IndexColumn) error

CreatePrimaryKey implements the PrimaryKeyAlterableTable

func (*Table) DataLength

func (t *Table) DataLength(ctx *sql.Context) (uint64, error)

func (*Table) DebugString

func (t *Table) DebugString() string

func (*Table) Deleter

func (t *Table) Deleter(ctx *sql.Context) sql.RowDeleter

func (*Table) DropCheck

func (t *Table) DropCheck(ctx *sql.Context, chName string) error

func (t *Table) DropCheck(ctx *sql.Context, chName string) error {} implements sql.CheckAlterableTable.

func (*Table) DropColumn

func (t *Table) DropColumn(ctx *sql.Context, columnName string) error

func (*Table) DropForeignKey

func (t *Table) DropForeignKey(ctx *sql.Context, fkName string) error

DropForeignKey implements sql.ForeignKeyAlterableTable.

func (*Table) DropIndex

func (t *Table) DropIndex(ctx *sql.Context, indexName string) error

DropIndex implements sql.IndexAlterableTable

func (*Table) DropPrimaryKey

func (t *Table) DropPrimaryKey(ctx *sql.Context) error

DropPrimaryKey implements the PrimaryKeyAlterableTable

func (*Table) EnablePrimaryKeyIndexes

func (t *Table) EnablePrimaryKeyIndexes()

EnablePrimaryKeyIndexes enables the use of primary key indexes on this table.

func (*Table) Filters

func (t *Table) Filters() []sql.Expression

Filters implements the sql.FilteredTable interface.

func (*Table) GetChecks

func (t *Table) GetChecks(_ *sql.Context) ([]sql.CheckDefinition, error)

GetChecks implements sql.CheckTable

func (*Table) GetForeignKeys

func (t *Table) GetForeignKeys(_ *sql.Context) ([]sql.ForeignKeyConstraint, error)

GetForeignKeys implements sql.ForeignKeyTable

func (*Table) GetIndexes

func (t *Table) GetIndexes(ctx *sql.Context) ([]sql.Index, error)

GetIndexes implements sql.IndexedTable

func (*Table) GetNextAutoIncrementValue

func (t *Table) GetNextAutoIncrementValue(ctx *sql.Context, insertVal interface{}) (interface{}, error)

GetNextAutoIncrementValue gets the next auto increment value for the memory table the increment.

func (*Table) GetPartition

func (t *Table) GetPartition(key string) []sql.Row

func (*Table) HandledFilters

func (t *Table) HandledFilters(filters []sql.Expression) []sql.Expression

HandledFilters implements the sql.FilteredTable interface.

func (*Table) IndexKeyValues

func (t *Table) IndexKeyValues(
	ctx *sql.Context,
	colNames []string,
) (sql.PartitionIndexKeyValueIter, error)

IndexKeyValues implements the sql.IndexableTable interface.

func (*Table) Insert

func (t *Table) Insert(ctx *sql.Context, row sql.Row) error

Convenience method to avoid having to create an inserter in test setup

func (*Table) Inserter

func (t *Table) Inserter(ctx *sql.Context) sql.RowInserter

func (*Table) ModifyColumn

func (t *Table) ModifyColumn(ctx *sql.Context, columnName string, column *sql.Column, order *sql.ColumnOrder) error

func (*Table) Name

func (t *Table) Name() string

Name implements the sql.Table interface.

func (*Table) NumRows

func (t *Table) NumRows(ctx *sql.Context) (uint64, error)

func (*Table) PartitionCount

func (t *Table) PartitionCount(ctx *sql.Context) (int64, error)

PartitionCount implements the sql.PartitionCounter interface.

func (*Table) PartitionRows

func (t *Table) PartitionRows(ctx *sql.Context, partition sql.Partition) (sql.RowIter, error)

PartitionRows implements the sql.PartitionRows interface.

func (*Table) Partitions

func (t *Table) Partitions(ctx *sql.Context) (sql.PartitionIter, error)

Partitions implements the sql.Table interface.

func (*Table) PeekNextAutoIncrementValue

func (t *Table) PeekNextAutoIncrementValue(*sql.Context) (interface{}, error)

PeekNextAutoIncrementValue peeks at the next AUTO_INCREMENT value

func (*Table) PrimaryKeySchema

func (t *Table) PrimaryKeySchema() sql.PrimaryKeySchema

PrimaryKeySchema implements sql.PrimaryKeyAlterableTable

func (*Table) RenameIndex

func (t *Table) RenameIndex(ctx *sql.Context, fromIndexName string, toIndexName string) error

RenameIndex implements sql.IndexAlterableTable

func (*Table) Replacer

func (t *Table) Replacer(ctx *sql.Context) sql.RowReplacer

func (*Table) Schema

func (t *Table) Schema() sql.Schema

Schema implements the sql.Table interface.

func (*Table) String

func (t *Table) String() string

String implements the sql.Table interface.

func (*Table) TableExists

func (t *Table) TableExists(name string) bool

func (*Table) Truncate

func (t *Table) Truncate(ctx *sql.Context) (int, error)

func (*Table) Updater

func (t *Table) Updater(ctx *sql.Context) sql.RowUpdater

func (*Table) WithIndexLookup

func (t *Table) WithIndexLookup(lookup sql.IndexLookup) sql.Table

WithIndexLookup implements the sql.IndexAddressableTable interface.

func (*Table) WithProjection

func (t *Table) WithProjection(colNames []string) sql.Table

WithProjection implements the sql.ProjectedTable interface.

type TestIndexDriver

type TestIndexDriver struct {
	// contains filtered or unexported fields
}

TestIndexDriver is a non-performant index driver meant to aid in verification of engine correctness. It can not create or delete indexes, but will use the index types defined in this package to alter how queries are executed, retrieving values from the indexes rather than from the tables directly.

func NewIndexDriver

func NewIndexDriver(db string, indexes map[string][]sql.DriverIndex) *TestIndexDriver

NewIndexDriver returns a new index driver for database and the indexes given, keyed by the table name.

func (*TestIndexDriver) Create

func (d *TestIndexDriver) Create(db, table, id string, expressions []sql.Expression, config map[string]string) (sql.DriverIndex, error)

func (*TestIndexDriver) Delete

func (*TestIndexDriver) ID

func (d *TestIndexDriver) ID() string

func (*TestIndexDriver) LoadAll

func (d *TestIndexDriver) LoadAll(ctx *sql.Context, db, table string) ([]sql.DriverIndex, error)

func (*TestIndexDriver) Save

Jump to

Keyboard shortcuts

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