r3sqlite3

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package r3sqlite3 provides an r3.CRUD[T, ID] driver backed by mattn/go-sqlite3, the CGo SQLite3 driver for database/sql.

Driver: github.com/mattn/go-sqlite3 Source: https://github.com/mattn/go-sqlite3

Supported r3 features:

  • Full CRUD (Create, Get, List, Update, Delete)
  • Filters, Sorts, Pagination via the r3 SQL dialect
  • Thread-safe default queries (SetDefaultListQuery, SetDefaultGetQuery)
  • Raw escape hatch (BaseRaw) for arbitrary SQL with ?-style placeholders

Limitations / notes:

  • No ORM layer: this driver builds raw SQL and uses reflection-based struct scanning. Model structs must use `db` struct tags (e.g. `db:"column_name,pk"`).
  • No preload support. Relations (joins, eager loading) must be done via Raw().
  • No soft-delete support. IncludeTrashed is ignored. Restore/HardDelete not available.
  • Table names are derived automatically from struct name (CamelCase -> snake_case + plural).
  • Nullable columns require pointer types (e.g. *string, *int64) in the model struct.
  • Uses `?` placeholders natively (no conversion needed).
  • ILIKE is not supported by SQLite; use LIKE instead (SQLite LIKE is case-insensitive for ASCII characters by default).
  • RETURNING clause requires SQLite 3.35+ (supported by go-sqlite3).
  • Transactions are supported via the r3.Transactor interface (BeginTx).
  • For advanced use cases (CTEs, etc.), use Raw().DB to access the underlying *sql.DB directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSqlite3Querier

func NewSqlite3Querier[T any, ID comparable](db *sql.DB, opts ...r3.Option) r3.Querier[T, ID]

NewSqlite3Querier creates a read-only SQLite-based repository. Returns r3.Querier — a compile-time guarantee of read-only access.

Types

type Sqlite3CRUD

type Sqlite3CRUD[T any, ID comparable] struct {
	*enginesql.BaseCRUD[T, ID]
}

Sqlite3CRUD is a CRUD repository based on database/sql with mattn/go-sqlite3. It embeds enginesql.BaseCRUD which provides the full r3.CRUD implementation.

func NewSqlite3CRUD

func NewSqlite3CRUD[T any, ID comparable](db *sql.DB, opts ...r3.Option) *Sqlite3CRUD[T, ID]

NewSqlite3CRUD creates a new SQLite-based CRUD repository. Models should use `db:"column_name"` struct tags for column mapping. The primary key field should be tagged with `db:"id,pk"` (defaults to "id").

Accepts optional r3.Option values for framework-level configuration.

func (*Sqlite3CRUD[T, ID]) DB

func (r *Sqlite3CRUD[T, ID]) DB() *sql.DB

DB returns the underlying *sql.DB for advanced usage.

func (*Sqlite3CRUD[T, ID]) Raw

func (r *Sqlite3CRUD[T, ID]) Raw() *enginesql.BaseRaw[T, ID]

Raw returns the BaseRaw escape hatch for custom queries.

type Sqlite3Raw deprecated

type Sqlite3Raw[T any, ID any] struct {
	*enginesql.BaseRaw[T, ID]
}

Sqlite3Raw is a thin wrapper around enginesql.BaseRaw for backward compatibility.

Deprecated: Use enginesql.BaseRaw directly via Sqlite3CRUD.Raw().

func NewSqlite3Raw

func NewSqlite3Raw[T any, ID comparable](db *sql.DB) *Sqlite3Raw[T, ID]

NewSqlite3Raw creates a new Sqlite3Raw instance.

func (*Sqlite3Raw[T, ID]) DB

func (r *Sqlite3Raw[T, ID]) DB() *sql.DB

DB returns the underlying *sql.DB for fully custom usage.

func (*Sqlite3Raw[T, ID]) Exec

func (r *Sqlite3Raw[T, ID]) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec executes a raw SQL query that does not return rows.

func (*Sqlite3Raw[T, ID]) Query

func (r *Sqlite3Raw[T, ID]) Query(ctx context.Context, query string, args ...any) ([]T, error)

Query executes a raw SQL query and scans results into a slice of T.

func (*Sqlite3Raw[T, ID]) QueryRow

func (r *Sqlite3Raw[T, ID]) QueryRow(ctx context.Context, query string, args ...any) (T, error)

QueryRow executes a raw SQL query expected to return a single row and scans it into T.

Jump to

Keyboard shortcuts

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