sqlite

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSQLiteMigrator

func NewSQLiteMigrator(db *sql.DB, sqliteDB *SQLiteDB) types.DatabaseMigrator

NewSQLiteMigrator creates a new SQLite migrator that implements types.DatabaseMigrator

func NewSQLiteRawQuery

func NewSQLiteRawQuery(driver *SQLiteDB, sql string, args ...any) types.RawQuery

NewSQLiteRawQuery creates a new SQLite raw query

Types

type SQLiteCapabilities

type SQLiteCapabilities struct{}

SQLiteCapabilities implements types.DriverCapabilities for SQLite

func NewSQLiteCapabilities

func NewSQLiteCapabilities() *SQLiteCapabilities

NewSQLiteCapabilities creates new SQLite capabilities

func (*SQLiteCapabilities) GetBooleanLiteral

func (c *SQLiteCapabilities) GetBooleanLiteral(value bool) string

func (*SQLiteCapabilities) GetDriverType

func (c *SQLiteCapabilities) GetDriverType() types.DriverType

func (*SQLiteCapabilities) GetNullsOrderingSQL

func (c *SQLiteCapabilities) GetNullsOrderingSQL(direction types.Order, nullsFirst bool) string

func (*SQLiteCapabilities) GetPlaceholder

func (c *SQLiteCapabilities) GetPlaceholder(index int) string

func (*SQLiteCapabilities) GetSupportedSchemes

func (c *SQLiteCapabilities) GetSupportedSchemes() []string

func (*SQLiteCapabilities) IsNoSQL

func (c *SQLiteCapabilities) IsNoSQL() bool

func (*SQLiteCapabilities) IsSystemIndex

func (c *SQLiteCapabilities) IsSystemIndex(indexName string) bool

func (*SQLiteCapabilities) IsSystemTable

func (c *SQLiteCapabilities) IsSystemTable(tableName string) bool

func (*SQLiteCapabilities) NeedsTypeConversion

func (c *SQLiteCapabilities) NeedsTypeConversion() bool

func (*SQLiteCapabilities) QuoteIdentifier

func (c *SQLiteCapabilities) QuoteIdentifier(name string) string

func (*SQLiteCapabilities) RequiresLimitForOffset

func (c *SQLiteCapabilities) RequiresLimitForOffset() bool

func (*SQLiteCapabilities) SupportsAggregationPipeline

func (c *SQLiteCapabilities) SupportsAggregationPipeline() bool

func (*SQLiteCapabilities) SupportsArrayFields

func (c *SQLiteCapabilities) SupportsArrayFields() bool

func (*SQLiteCapabilities) SupportsDefaultValues

func (c *SQLiteCapabilities) SupportsDefaultValues() bool

func (*SQLiteCapabilities) SupportsDistinctOn

func (c *SQLiteCapabilities) SupportsDistinctOn() bool

func (*SQLiteCapabilities) SupportsForeignKeys added in v0.6.0

func (c *SQLiteCapabilities) SupportsForeignKeys() bool

func (*SQLiteCapabilities) SupportsNestedDocuments

func (c *SQLiteCapabilities) SupportsNestedDocuments() bool

func (*SQLiteCapabilities) SupportsReturning

func (c *SQLiteCapabilities) SupportsReturning() bool

func (*SQLiteCapabilities) SupportsTransactions

func (c *SQLiteCapabilities) SupportsTransactions() bool

type SQLiteDB

type SQLiteDB struct {
	*base.Driver
	// contains filtered or unexported fields
}

SQLiteDB implements the Database interface for SQLite

func NewSQLiteDB

func NewSQLiteDB(nativeURI string) (*SQLiteDB, error)

NewSQLiteDB creates a new SQLite database instance The uri parameter should be a native SQLite path (e.g., "/path/to/db.sqlite" or ":memory:")

func (*SQLiteDB) Begin

func (s *SQLiteDB) Begin(ctx context.Context) (types.Transaction, error)

Begin starts a new transaction

func (*SQLiteDB) Connect

func (s *SQLiteDB) Connect(ctx context.Context) error

Connect establishes connection to SQLite database

func (*SQLiteDB) CreateModel

func (s *SQLiteDB) CreateModel(ctx context.Context, modelName string) error

CreateModel creates a table for the given model

func (*SQLiteDB) DropModel

func (s *SQLiteDB) DropModel(ctx context.Context, modelName string) error

DropModel drops the table for the given model

func (*SQLiteDB) GetCapabilities

func (s *SQLiteDB) GetCapabilities() types.DriverCapabilities

GetCapabilities returns driver capabilities

func (*SQLiteDB) GetDriverType

func (s *SQLiteDB) GetDriverType() string

GetDriverType returns the database driver type

func (*SQLiteDB) GetMigrator

func (s *SQLiteDB) GetMigrator() types.DatabaseMigrator

GetMigrator returns a migrator for SQLite

func (*SQLiteDB) Model

func (s *SQLiteDB) Model(modelName string) types.ModelQuery

Model creates a new model query

func (*SQLiteDB) Raw

func (s *SQLiteDB) Raw(sql string, args ...any) types.RawQuery

Raw creates a new raw query

func (*SQLiteDB) SyncSchemas

func (s *SQLiteDB) SyncSchemas(ctx context.Context) error

SyncSchemas synchronizes all loaded schemas with the database

func (*SQLiteDB) Transaction

func (s *SQLiteDB) Transaction(ctx context.Context, fn func(tx types.Transaction) error) error

Transaction executes a function within a transaction

type SQLiteMigrator

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

SQLiteMigrator implements types.DatabaseSpecificMigrator for SQLite

func (*SQLiteMigrator) ApplyMigration

func (m *SQLiteMigrator) ApplyMigration(sql string) error

ApplyMigration executes a migration SQL

func (*SQLiteMigrator) ConvertFieldToColumnInfo

func (m *SQLiteMigrator) ConvertFieldToColumnInfo(field schema.Field) *types.ColumnInfo

ConvertFieldToColumnInfo converts a schema field to column info

func (*SQLiteMigrator) FormatDefaultValue

func (m *SQLiteMigrator) FormatDefaultValue(value any) string

FormatDefaultValue formats a default value for SQLite

func (*SQLiteMigrator) GenerateAddColumnSQL

func (m *SQLiteMigrator) GenerateAddColumnSQL(tableName string, field any) (string, error)

GenerateAddColumnSQL generates ADD COLUMN SQL

func (*SQLiteMigrator) GenerateColumnDefinitionFromColumnInfo

func (m *SQLiteMigrator) GenerateColumnDefinitionFromColumnInfo(col types.ColumnInfo) string

GenerateColumnDefinitionFromColumnInfo generates column definition from ColumnInfo

func (*SQLiteMigrator) GenerateCreateIndexSQL

func (m *SQLiteMigrator) GenerateCreateIndexSQL(tableName, indexName string, columns []string, unique bool) string

GenerateCreateIndexSQL generates CREATE INDEX SQL

func (*SQLiteMigrator) GenerateCreateTableSQL

func (m *SQLiteMigrator) GenerateCreateTableSQL(s *schema.Schema) (string, error)

GenerateCreateTableSQL generates CREATE TABLE SQL from schema (for DatabaseSpecificMigrator)

func (*SQLiteMigrator) GenerateDropColumnSQL

func (m *SQLiteMigrator) GenerateDropColumnSQL(tableName, columnName string) ([]string, error)

GenerateDropColumnSQL generates DROP COLUMN SQL

func (*SQLiteMigrator) GenerateDropIndexSQL

func (m *SQLiteMigrator) GenerateDropIndexSQL(indexName string) string

GenerateDropIndexSQL generates DROP INDEX SQL

func (*SQLiteMigrator) GenerateDropTableSQL

func (m *SQLiteMigrator) GenerateDropTableSQL(tableName string) string

GenerateDropTableSQL generates DROP TABLE SQL

func (*SQLiteMigrator) GenerateModifyColumnSQL

func (m *SQLiteMigrator) GenerateModifyColumnSQL(change types.ColumnChange) ([]string, error)

GenerateModifyColumnSQL generates SQL to modify a column (not directly supported in SQLite)

func (*SQLiteMigrator) GetDatabaseType

func (m *SQLiteMigrator) GetDatabaseType() string

GetDatabaseType returns the database type

func (*SQLiteMigrator) GetTableInfo

func (m *SQLiteMigrator) GetTableInfo(tableName string) (*types.TableInfo, error)

GetTableInfo returns table information

func (*SQLiteMigrator) GetTables

func (m *SQLiteMigrator) GetTables() ([]string, error)

GetTables returns all table names

func (*SQLiteMigrator) IsPrimaryKeyIndex added in v0.6.0

func (m *SQLiteMigrator) IsPrimaryKeyIndex(indexName string) bool

IsPrimaryKeyIndex checks if an index name indicates it's a primary key index

func (*SQLiteMigrator) IsSystemIndex

func (m *SQLiteMigrator) IsSystemIndex(indexName string) bool

IsSystemIndex checks if an index is a system-generated index in SQLite

func (*SQLiteMigrator) IsSystemTable

func (m *SQLiteMigrator) IsSystemTable(tableName string) bool

IsSystemTable checks if a table is a system table in SQLite

func (*SQLiteMigrator) MapDatabaseTypeToFieldType added in v0.6.0

func (m *SQLiteMigrator) MapDatabaseTypeToFieldType(dbType string) schema.FieldType

MapDatabaseTypeToFieldType converts SQLite column types to schema field types

func (*SQLiteMigrator) MapFieldType

func (m *SQLiteMigrator) MapFieldType(field schema.Field) string

MapFieldType maps schema field types to SQLite types

func (*SQLiteMigrator) NormalizeDefaultToPrismaFunction added in v0.6.0

func (m *SQLiteMigrator) NormalizeDefaultToPrismaFunction(value any, fieldType schema.FieldType) (string, bool)

NormalizeDefaultToPrismaFunction converts normalized defaults to Prisma function names

func (*SQLiteMigrator) ParseDefaultValue added in v0.6.0

func (m *SQLiteMigrator) ParseDefaultValue(value any, fieldType schema.FieldType) any

ParseDefaultValue parses SQLite-specific default values to normalized form

type SQLiteMigratorWrapper

type SQLiteMigratorWrapper struct {
	*base.BaseMigrator
	// contains filtered or unexported fields
}

SQLiteMigratorWrapper wraps SQLiteMigrator with BaseMigrator to implement types.DatabaseMigrator

func (*SQLiteMigratorWrapper) CompareSchema

func (w *SQLiteMigratorWrapper) CompareSchema(existingTable *types.TableInfo, desiredSchema any) (*types.MigrationPlan, error)

CompareSchema wraps the BaseMigrator's CompareSchema to match the DatabaseMigrator interface

func (*SQLiteMigratorWrapper) GenerateAddColumnSQL

func (w *SQLiteMigratorWrapper) GenerateAddColumnSQL(tableName string, field any) (string, error)

GenerateAddColumnSQL wraps to match the DatabaseMigrator interface

func (*SQLiteMigratorWrapper) GenerateCreateTableSQL

func (w *SQLiteMigratorWrapper) GenerateCreateTableSQL(schemaInterface any) (string, error)

GenerateCreateTableSQL wraps to match the DatabaseMigrator interface

func (*SQLiteMigratorWrapper) GetSpecific added in v0.6.0

GetSpecific returns the specific migrator implementation

func (*SQLiteMigratorWrapper) IsSystemTable

func (w *SQLiteMigratorWrapper) IsSystemTable(tableName string) bool

IsSystemTable delegates to the specific implementation

type SQLiteRawQuery

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

SQLiteRawQuery implements the RawQuery interface for SQLite

func (*SQLiteRawQuery) Exec

func (q *SQLiteRawQuery) Exec(ctx context.Context) (types.Result, error)

Exec executes the raw query and returns the result

func (*SQLiteRawQuery) Find

func (q *SQLiteRawQuery) Find(ctx context.Context, dest any) error

Find executes the raw query and returns multiple results

func (*SQLiteRawQuery) FindOne

func (q *SQLiteRawQuery) FindOne(ctx context.Context, dest any) error

FindOne executes the raw query and returns a single result

type SQLiteTransaction

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

SQLiteTransaction implements the Transaction interface for SQLite

func NewSQLiteTransaction

func NewSQLiteTransaction(tx *sql.Tx, database *SQLiteDB) *SQLiteTransaction

NewSQLiteTransaction creates a new SQLite transaction

func (*SQLiteTransaction) Commit

func (t *SQLiteTransaction) Commit(ctx context.Context) error

Commit commits the transaction

func (*SQLiteTransaction) CreateMany

func (t *SQLiteTransaction) CreateMany(ctx context.Context, modelName string, data []any) (types.Result, error)

CreateMany performs batch insert within the transaction

func (*SQLiteTransaction) DeleteMany

func (t *SQLiteTransaction) DeleteMany(ctx context.Context, modelName string, condition types.Condition) (types.Result, error)

DeleteMany performs batch delete within the transaction

func (*SQLiteTransaction) Model

func (t *SQLiteTransaction) Model(modelName string) types.ModelQuery

Model creates a new model query within the transaction

func (*SQLiteTransaction) Raw

func (t *SQLiteTransaction) Raw(sql string, args ...any) types.RawQuery

Raw creates a new raw query within the transaction

func (*SQLiteTransaction) Rollback

func (t *SQLiteTransaction) Rollback(ctx context.Context) error

Rollback rolls back the transaction

func (*SQLiteTransaction) RollbackTo

func (t *SQLiteTransaction) RollbackTo(ctx context.Context, name string) error

RollbackTo rolls back to a savepoint

func (*SQLiteTransaction) Savepoint

func (t *SQLiteTransaction) Savepoint(ctx context.Context, name string) error

Savepoint creates a savepoint (SQLite supports nested transactions via savepoints)

func (*SQLiteTransaction) UpdateMany

func (t *SQLiteTransaction) UpdateMany(ctx context.Context, modelName string, condition types.Condition, data any) (types.Result, error)

UpdateMany performs batch update within the transaction

type SQLiteTransactionDB

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

SQLiteTransactionDB wraps the transaction for database operations

func (*SQLiteTransactionDB) Begin

func (*SQLiteTransactionDB) Close

func (td *SQLiteTransactionDB) Close() error

func (*SQLiteTransactionDB) Connect

func (td *SQLiteTransactionDB) Connect(ctx context.Context) error

All Database interface methods that delegate to the transaction

func (*SQLiteTransactionDB) CreateModel

func (td *SQLiteTransactionDB) CreateModel(ctx context.Context, modelName string) error

func (*SQLiteTransactionDB) DropModel

func (td *SQLiteTransactionDB) DropModel(ctx context.Context, modelName string) error

func (*SQLiteTransactionDB) Exec

func (td *SQLiteTransactionDB) Exec(query string, args ...any) (sql.Result, error)

func (*SQLiteTransactionDB) GetCapabilities

func (td *SQLiteTransactionDB) GetCapabilities() types.DriverCapabilities

func (*SQLiteTransactionDB) GetDriverType

func (td *SQLiteTransactionDB) GetDriverType() string

func (*SQLiteTransactionDB) GetLogger added in v0.4.0

func (td *SQLiteTransactionDB) GetLogger() logger.Logger

func (*SQLiteTransactionDB) GetMigrator

func (td *SQLiteTransactionDB) GetMigrator() types.DatabaseMigrator

func (*SQLiteTransactionDB) GetModelSchema

func (td *SQLiteTransactionDB) GetModelSchema(modelName string) (*schema.Schema, error)

func (*SQLiteTransactionDB) GetModels

func (td *SQLiteTransactionDB) GetModels() []string

func (*SQLiteTransactionDB) GetSchema

func (td *SQLiteTransactionDB) GetSchema(modelName string) (*schema.Schema, error)

func (*SQLiteTransactionDB) LoadSchema

func (td *SQLiteTransactionDB) LoadSchema(ctx context.Context, schemaContent string) error

LoadSchema is not supported within a transaction

func (*SQLiteTransactionDB) LoadSchemaFrom

func (td *SQLiteTransactionDB) LoadSchemaFrom(ctx context.Context, filename string) error

LoadSchemaFrom is not supported within a transaction

func (*SQLiteTransactionDB) Model

func (td *SQLiteTransactionDB) Model(modelName string) types.ModelQuery

func (*SQLiteTransactionDB) Ping

func (td *SQLiteTransactionDB) Ping(ctx context.Context) error

func (*SQLiteTransactionDB) Query

func (td *SQLiteTransactionDB) Query(query string, args ...any) (*sql.Rows, error)

func (*SQLiteTransactionDB) QueryRow

func (td *SQLiteTransactionDB) QueryRow(query string, args ...any) *sql.Row

func (*SQLiteTransactionDB) Raw

func (td *SQLiteTransactionDB) Raw(sql string, args ...any) types.RawQuery

func (*SQLiteTransactionDB) RegisterSchema

func (td *SQLiteTransactionDB) RegisterSchema(modelName string, schema *schema.Schema) error

func (*SQLiteTransactionDB) ResolveFieldName

func (td *SQLiteTransactionDB) ResolveFieldName(modelName, fieldName string) (string, error)

func (*SQLiteTransactionDB) ResolveFieldNames

func (td *SQLiteTransactionDB) ResolveFieldNames(modelName string, fieldNames []string) ([]string, error)

func (*SQLiteTransactionDB) ResolveTableName

func (td *SQLiteTransactionDB) ResolveTableName(modelName string) (string, error)

func (*SQLiteTransactionDB) SetLogger added in v0.4.0

func (td *SQLiteTransactionDB) SetLogger(l logger.Logger)

func (*SQLiteTransactionDB) SyncSchemas

func (td *SQLiteTransactionDB) SyncSchemas(ctx context.Context) error

SyncSchemas is not supported within a transaction

func (*SQLiteTransactionDB) Transaction

func (td *SQLiteTransactionDB) Transaction(ctx context.Context, fn func(tx types.Transaction) error) error

type SQLiteTransactionRawQuery

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

SQLiteTransactionRawQuery implements RawQuery for transactions

func (*SQLiteTransactionRawQuery) Exec

func (*SQLiteTransactionRawQuery) Find

func (q *SQLiteTransactionRawQuery) Find(ctx context.Context, dest any) error

func (*SQLiteTransactionRawQuery) FindOne

func (q *SQLiteTransactionRawQuery) FindOne(ctx context.Context, dest any) error

type SQLiteURIParser

type SQLiteURIParser struct{}

SQLiteURIParser implements URIParser for SQLite databases

func NewSQLiteURIParser

func NewSQLiteURIParser() *SQLiteURIParser

NewSQLiteURIParser creates a new SQLite URI parser

func (*SQLiteURIParser) GetDriverType

func (p *SQLiteURIParser) GetDriverType() string

GetDriverType returns the driver type this parser is for

func (*SQLiteURIParser) GetSupportedSchemes

func (p *SQLiteURIParser) GetSupportedSchemes() []string

GetSupportedSchemes returns the URI schemes this parser supports

func (*SQLiteURIParser) ParseURI

func (p *SQLiteURIParser) ParseURI(uri string) (string, error)

ParseURI parses a SQLite URI and returns a native SQLite file path Supported formats:

  • sqlite:///path/to/database.db
  • sqlite://:memory:
  • sqlite://file::memory:?cache=shared
  • sqlite:///absolute/path/database.db
  • sqlite://relative/path/database.db

Jump to

Keyboard shortcuts

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