gormsqlite

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Vendored from github.com/glebarez/sqlite v1.11.0 (MIT) with the only change being package rename from `sqlite` to `gormsqlite`. We vendor this in-tree to avoid importing github.com/glebarez/sqlite itself, which pulls github.com/glebarez/go-sqlite — a fork of modernc.org/sqlite. The user directive is to depend strictly on modernc.org/sqlite; these migrator helpers are pure SQL/GORM glue with no SQLite driver dependency.

Package gormsqlite is an in-tree GORM dialector that uses modernc.org/sqlite as its SQL driver.

We maintain our own small dialector rather than pulling in `gorm.io/driver/sqlite` (which hard-requires mattn/go-sqlite3) or `github.com/glebarez/sqlite` (which hard-requires a fork of modernc under a different import path). The resulting build tree references modernc.org/sqlite exclusively for its SQLite needs.

The bulk of this dialector is structural boilerplate adapted from the glebarez/sqlite code (Apache-2.0); the only functional change is that the driver registration (`_ "modernc.org/sqlite"`) and Translate()'s error type come directly from modernc.org/sqlite.

Vendored from github.com/glebarez/sqlite v1.11.0 (MIT) with the only change being package rename from `sqlite` to `gormsqlite`. We vendor this in-tree to avoid importing github.com/glebarez/sqlite itself, which pulls github.com/glebarez/go-sqlite — a fork of modernc.org/sqlite. The user directive is to depend strictly on modernc.org/sqlite; these migrator helpers are pure SQL/GORM glue with no SQLite driver dependency.

Vendored from github.com/glebarez/sqlite v1.11.0 (MIT) with the only change being package rename from `sqlite` to `gormsqlite`. We vendor this in-tree to avoid importing github.com/glebarez/sqlite itself, which pulls github.com/glebarez/go-sqlite — a fork of modernc.org/sqlite. The user directive is to depend strictly on modernc.org/sqlite; these migrator helpers are pure SQL/GORM glue with no SQLite driver dependency.

Index

Constants

View Source
const DriverName = "sqlite"

DriverName is the database/sql driver name registered by modernc.org/sqlite (pure-Go SQLite).

Variables

View Source
var (
	ErrConstraintsNotImplemented = errors.New("constraints not implemented on sqlite, consider using DisableForeignKeyConstraintWhenMigrating, more details https://github.com/go-gorm/gorm/wiki/GORM-V2-Release-Note-Draft#all-new-migrator")
)

Functions

func Open

func Open(dsn string) gorm.Dialector

Open returns a Dialector that opens the database lazily from the given DSN.

Types

type Dialector

type Dialector struct {
	DriverName string
	DSN        string
	Conn       gorm.ConnPool
}

Dialector is a GORM dialector backed exclusively by modernc.org/sqlite.

func (Dialector) BindVarTo

func (Dialector) BindVarTo(writer clause.Writer, _ *gorm.Statement, _ interface{})

func (Dialector) ClauseBuilders

func (dialector Dialector) ClauseBuilders() map[string]clause.ClauseBuilder

func (Dialector) DataTypeOf

func (Dialector) DataTypeOf(field *schema.Field) string

func (Dialector) DefaultValueOf

func (Dialector) DefaultValueOf(field *schema.Field) clause.Expression

func (Dialector) Explain

func (Dialector) Explain(sql string, vars ...interface{}) string

func (Dialector) Initialize

func (dialector Dialector) Initialize(db *gorm.DB) (err error)

func (Dialector) Migrator

func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator

func (Dialector) Name

func (Dialector) Name() string

func (Dialector) QuoteTo

func (Dialector) QuoteTo(writer clause.Writer, str string)

func (Dialector) RollbackTo

func (Dialector) RollbackTo(tx *gorm.DB, name string) error

func (Dialector) SavePoint

func (Dialector) SavePoint(tx *gorm.DB, name string) error

func (Dialector) Translate

func (Dialector) Translate(err error) error

Translate maps modernc.org/sqlite constraint errors onto GORM's canonical error types so consumers can errors.Is(err, gorm.ErrDuplicatedKey) etc.

type Index

type Index struct {
	Seq     int
	Name    string
	Unique  bool
	Origin  string
	Partial bool
}

type Migrator

type Migrator struct {
	migrator.Migrator
}

func (Migrator) AlterColumn

func (m Migrator) AlterColumn(value interface{}, name string) error

func (Migrator) BuildIndexOptions

func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{})

func (Migrator) ColumnTypes

func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)

ColumnTypes return columnTypes []gorm.ColumnType and execErr error

func (Migrator) CreateConstraint

func (m Migrator) CreateConstraint(value interface{}, name string) error

func (Migrator) CreateIndex

func (m Migrator) CreateIndex(value interface{}, name string) error

func (Migrator) CurrentDatabase

func (m Migrator) CurrentDatabase() (name string)

func (Migrator) DropColumn

func (m Migrator) DropColumn(value interface{}, name string) error

func (Migrator) DropConstraint

func (m Migrator) DropConstraint(value interface{}, name string) error

func (Migrator) DropIndex

func (m Migrator) DropIndex(value interface{}, name string) error

func (Migrator) DropTable

func (m Migrator) DropTable(values ...interface{}) error

func (Migrator) GetIndexes

func (m Migrator) GetIndexes(value interface{}) ([]gorm.Index, error)

GetIndexes return Indexes []gorm.Index and execErr error, See the doc

func (Migrator) GetTables

func (m Migrator) GetTables() (tableList []string, err error)

func (Migrator) HasColumn

func (m Migrator) HasColumn(value interface{}, name string) bool

func (Migrator) HasConstraint

func (m Migrator) HasConstraint(value interface{}, name string) bool

func (Migrator) HasIndex

func (m Migrator) HasIndex(value interface{}, name string) bool

func (Migrator) HasTable

func (m Migrator) HasTable(value interface{}) bool

func (Migrator) RenameIndex

func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error

func (*Migrator) RunWithoutForeignKey

func (m *Migrator) RunWithoutForeignKey(fc func() error) error

Jump to

Keyboard shortcuts

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