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 ¶
- func NewSqlite3Querier[T any, ID comparable](db *sql.DB, opts ...r3.Option) r3.Querier[T, ID]
- type Sqlite3CRUD
- type Sqlite3Rawdeprecated
- func (r *Sqlite3Raw[T, ID]) DB() *sql.DB
- func (r *Sqlite3Raw[T, ID]) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (r *Sqlite3Raw[T, ID]) Query(ctx context.Context, query string, args ...any) ([]T, error)
- func (r *Sqlite3Raw[T, ID]) QueryRow(ctx context.Context, query string, args ...any) (T, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSqlite3Querier ¶
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
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.