sqlite

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 15 Imported by: 0

README

SQLite

This is a no CGO sqlite driver for GOE ORM based on https://pkg.go.dev/modernc.org/sqlite.

Features

  • 🪝 Connection Hook
  • 🧪 In Memory Database

Usage

Basic
package main

import (
	"github.com/go-goe/goe"
	"github.com/go-goe/sqlite"
)

type User struct {
	ID    int
	Name  string
	Email string `goe:"unique"`
}

type Database struct {
	User *User
	*goe.DB
}

func main() {
	db, err := goe.Open[Database](sqlite.Open("goe.db", sqlite.NewConfig(sqlite.Config{})))
}
Connection Hook
package main

import (
	"github.com/go-goe/goe"
	"github.com/go-goe/sqlite"
)

type User struct {
	ID    int
	Name  string
	Email string `goe:"unique"`
}

type Database struct {
	User *User
	*goe.DB
}

func main() {
	db, err := goe.Open[Database](sqlite.Open(filepath.Join(os.TempDir(), "goe.db"), sqlite.NewConfig(
		sqlite.Config{
			ConnectionHook: func(conn sqlite.ExecQuerierContext, dsn string) error {
				conn.ExecContext(context.Background(), "PRAGMA foreign_keys = OFF;", nil)
				return nil
			},
		},
	)))
}
In Memory Database
package main

import (
	"github.com/go-goe/goe"
	"github.com/go-goe/sqlite"
)

type User struct {
	ID    int
	Name  string
	Email string `goe:"unique"`
}

type Database struct {
	User *User
	*goe.DB
}

func main() {
	db, err := goe.Open[Database](sqlite.OpenInMemory(sqlite.NewConfig(sqlite.Config{})))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConfig added in v0.5.0

func NewConfig(c Config) config

Types

type Config

type Config struct {
	Logger           model.Logger
	IncludeArguments bool          // include all arguments used on query
	QueryThreshold   time.Duration // query threshold to warning on slow queries

	MigratePath    string         // output sql file, if defined the driver will not auto apply the migration.
	ConnectionHook ConnectionHook // ConnectionHook is called after each connection is opened.
}

type Connection

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

func (Connection) ExecContext

func (c Connection) ExecContext(ctx context.Context, query *model.Query) error

func (Connection) QueryContext

func (c Connection) QueryContext(ctx context.Context, query *model.Query) (model.Rows, error)

func (Connection) QueryRowContext

func (c Connection) QueryRowContext(ctx context.Context, query *model.Query) model.Row

type ConnectionHook added in v0.5.0

type ConnectionHook func(
	conn ExecQuerierContext,
	dsn string,
) error

type Driver

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

func Open

func Open(dns string, c config) (driver *Driver)

Open opens a sqlite connection. By default uses "PRAGMA foreign_keys = ON;" and "PRAGMA busy_timeout = 5000;".

func OpenInMemory added in v0.5.0

func OpenInMemory(c config) (driver *Driver)

OpenInMemory opens a in memory database.

func (*Driver) Close

func (dr *Driver) Close() error

func (*Driver) DropColumn

func (db *Driver) DropColumn(schema, table, column string) error

func (*Driver) DropTable

func (db *Driver) DropTable(schema, table string) error

func (*Driver) ErrorTranslator added in v0.5.0

func (dr *Driver) ErrorTranslator() func(err error) error

func (*Driver) GetDatabaseConfig added in v0.2.0

func (d *Driver) GetDatabaseConfig() *model.DatabaseConfig

func (*Driver) Init

func (dr *Driver) Init() error

func (*Driver) KeywordHandler

func (dr *Driver) KeywordHandler(s string) string

func (*Driver) MigrateContext

func (db *Driver) MigrateContext(ctx context.Context, migrator *model.Migrator) error

func (*Driver) Name

func (dr *Driver) Name() string

func (*Driver) NewConnection

func (dr *Driver) NewConnection() model.Connection

func (*Driver) NewTransaction

func (dr *Driver) NewTransaction(ctx context.Context, opts *sql.TxOptions) (model.Transaction, error)

func (*Driver) RenameColumn

func (db *Driver) RenameColumn(schema, table, oldColumn, newColumn string) error

func (*Driver) RenameTable added in v0.4.0

func (db *Driver) RenameTable(schema, table, newTable string) error

func (*Driver) Stats

func (dr *Driver) Stats() sql.DBStats

type ExecQuerierContext added in v0.5.0

type ExecQuerierContext interface {
	driver.ExecerContext
	driver.QueryerContext
}

type Row

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

func (Row) Scan

func (r Row) Scan(dest ...any) error

type Rows

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

func (Rows) Close

func (rs Rows) Close() error

func (Rows) Next

func (rs Rows) Next() bool

func (Rows) Scan

func (rs Rows) Scan(dest ...any) error

type Transaction

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

func (Transaction) Commit

func (t Transaction) Commit() error

func (Transaction) ExecContext

func (t Transaction) ExecContext(ctx context.Context, query *model.Query) error

func (Transaction) QueryContext

func (t Transaction) QueryContext(ctx context.Context, query *model.Query) (model.Rows, error)

func (Transaction) QueryRowContext

func (t Transaction) QueryRowContext(ctx context.Context, query *model.Query) model.Row

func (Transaction) Rollback

func (t Transaction) Rollback() error

Jump to

Keyboard shortcuts

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