sqlite

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

Provider implements the Provider interface for SQLite

func New

func New() *Provider

New creates a new SQLite provider

func (*Provider) ConvertFieldType

func (p *Provider) ConvertFieldType(field *types.Field) string

ConvertFieldType converts YAML field type to SQLite-specific SQL type

func (*Provider) GenerateAddColumn

func (p *Provider) GenerateAddColumn(tableName string, field *types.Field) string

GenerateAddColumn generates ALTER TABLE ADD COLUMN statement. The DEFAULT clause is emitted when field.Default is non-empty (already resolved from symbolic keys by resolveFieldDefault before this is called).

func (*Provider) GenerateAlterColumn

func (p *Provider) GenerateAlterColumn(tableName string, oldField, newField *types.Field) (string, error)

func (*Provider) GenerateAlterColumnWithTable

func (p *Provider) GenerateAlterColumnWithTable(currentTable *types.Table, fromField, toField *types.Field) (string, error)

GenerateAlterColumnWithTable implements providers.TableRecreationProvider. SQLite does not support ALTER COLUMN natively, so this method recreates the table with the new column definition: creates a temp table, copies all rows, drops the original, renames the temp table, and recreates any indexes.

func (*Provider) GenerateCreateIndex

func (p *Provider) GenerateCreateIndex(index *types.Index, tableName string) string

GenerateCreateIndex generates CREATE INDEX statement for SQLite. SQLite supports WHERE clauses for partial indexes but does not support Method (USING clause).

func (*Provider) GenerateCreateTable

func (p *Provider) GenerateCreateTable(schema *types.Schema, table *types.Table) (string, error)

func (*Provider) GenerateDropColumn

func (p *Provider) GenerateDropColumn(tableName, columnName string) string

GenerateDropColumn generates ALTER TABLE DROP COLUMN statement for SQLite. Requires SQLite 3.35.0+ (released 2021-03-12).

func (*Provider) GenerateDropForeignKeyConstraint

func (p *Provider) GenerateDropForeignKeyConstraint(tableName, constraintName string) string

func (*Provider) GenerateDropIndex

func (p *Provider) GenerateDropIndex(indexName, tableName string) string

GenerateDropIndex generates DROP INDEX statement for SQLite

func (*Provider) GenerateDropTable

func (p *Provider) GenerateDropTable(tableName string) string

GenerateDropTable generates DROP TABLE statement

func (*Provider) GenerateDropTableCascade

func (p *Provider) GenerateDropTableCascade(tableName string) string

GenerateDropTableCascade generates a DROP TABLE statement for SQLite. SQLite does not support CASCADE on DROP TABLE, so this is an alias for GenerateDropTable.

func (*Provider) GenerateForeignKeyConstraint

func (p *Provider) GenerateForeignKeyConstraint(tableName, fieldName, referencedTable, constraintName, onDelete, onUpdate string) string

func (*Provider) GenerateForeignKeyConstraints

func (p *Provider) GenerateForeignKeyConstraints(schema *types.Schema, junctionTables []types.Table) string

func (*Provider) GenerateIndexes

func (p *Provider) GenerateIndexes(schema *types.Schema) string

func (*Provider) GenerateJunctionTable

func (p *Provider) GenerateJunctionTable(table1, table2 string, schema *types.Schema) (string, error)

func (*Provider) GenerateRenameColumn

func (p *Provider) GenerateRenameColumn(tableName, oldName, newName string) string

GenerateRenameColumn generates ALTER TABLE RENAME COLUMN statement for SQLite. Requires SQLite 3.25.0+ (released 2018-09-15).

func (*Provider) GenerateRenameTable

func (p *Provider) GenerateRenameTable(oldName, newName string) string

GenerateRenameTable generates ALTER TABLE RENAME statement

func (*Provider) GenerateUpsert

func (p *Provider) GenerateUpsert(table string, conflictKeys []string, columns []string, valueLiterals [][]string) string

GenerateUpsert generates an INSERT ... ON CONFLICT DO UPDATE SET statement for SQLite. If all columns are conflict keys, it uses DO NOTHING instead. The valueLiterals are pre-formatted SQL literals and are not re-quoted.

func (*Provider) GetDatabaseSchema

func (p *Provider) GetDatabaseSchema(connectionString string) (*types.Schema, error)

GetDatabaseSchema extracts schema information from a SQLite database

func (*Provider) GetDefaultValue

func (p *Provider) GetDefaultValue(defaultRef string, defaults map[string]string) (string, error)

GetDefaultValue converts default value references to SQLite-specific values

func (*Provider) HistoryTableDDL

func (p *Provider) HistoryTableDDL() string

HistoryTableDDL returns the CREATE TABLE IF NOT EXISTS statement for the morphic_history migration-tracking table, using this provider's SQL dialect.

func (*Provider) InferForeignKeyType

func (p *Provider) InferForeignKeyType(referencedTable string, schema *types.Schema) string

func (*Provider) IsAlreadyExistsError

func (p *Provider) IsAlreadyExistsError(err error) bool

IsAlreadyExistsError returns true when err indicates an object already exists in the database.

func (*Provider) IsNotFoundError

func (p *Provider) IsNotFoundError(err error) bool

IsNotFoundError returns true when err is a SQLite "no such table/column/index" error.

func (*Provider) Placeholder

func (p *Provider) Placeholder(_ int) string

Placeholder returns the bind-parameter placeholder for the nth argument (1-indexed).

func (*Provider) QuoteName

func (p *Provider) QuoteName(name string) string

QuoteName quotes database identifiers for SQLite

func (*Provider) SetTypeMappings

func (p *Provider) SetTypeMappings(mappings map[string]string)

SetTypeMappings sets user-defined type mappings for this provider.

func (*Provider) SupportsOperation

func (p *Provider) SupportsOperation(operation string) bool

SupportsOperation checks if SQLite supports a specific operation. DROP_COLUMN requires SQLite 3.35.0+ (2021); RENAME_COLUMN requires 3.25.0+ (2018). ALTER_COLUMN is never supported natively — use GenerateAlterColumnWithTable instead.

Jump to

Keyboard shortcuts

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