Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyCursor(cursor *Cursor, paramOffset int) (string, []any)
- func ApplyPagination(limit, offset, paramOffset int) (string, []any)
- func BuildCount(tableName string, whereSql string, whereArgs []any) (string, []any)
- func BuildDelete(tableName string, whereSql string, whereArgs []any) (string, []any)
- func BuildInsert(tableName string, data map[string]any) (string, []any)
- func BuildOrderBy(orderBy map[string]string, table *tenant.SchemaTable) (string, error)
- func BuildRowPolicy(expression string, claims *tenant.AuthClaims, paramOffset int) (string, []any, error)
- func BuildSelect(tableName string, columns []string, whereSql string, whereArgs []any, ...) (string, []any)
- func BuildUpdate(tableName string, data map[string]any, whereSql string, whereArgs []any) (string, []any)
- func BuildWhere(where map[string]any, table *tenant.SchemaTable, paramOffset int) (string, []any, error)
- func EncodeCursor(column string, value any, direction string) string
- func NormalizeRow(row map[string]any, loc *time.Location)
- func QueryMaps(ctx context.Context, q tenant.Querier, loc *time.Location, stmt string, ...) ([]map[string]any, error)
- func QuoteIdent(name string) string
- func ResolveIncludes(ctx context.Context, dbPool tenant.Querier, mainTableUUID string, ...) error
- func ScanAllRowsToMaps(rows *sql.Rows, loc *time.Location) ([]map[string]any, error)
- type Cursor
- type IncludeAuthorizer
- type IncludeRequest
Constants ¶
const MaxLimit = 100
Variables ¶
var ErrIncludeForbidden = fmt.Errorf("included table is not accessible")
ErrIncludeForbidden is returned when the authorizer rejects a table.
Functions ¶
func ApplyPagination ¶
func BuildCount ¶
func BuildDelete ¶
func BuildInsert ¶
BuildInsert returns SQL and args for an INSERT, plus the deterministically-ordered column list. SQLite has no RETURNING * across all versions; callers should look up the inserted row via last_insert_rowid() (see ReadInsertedRow in helpers).
Column order is alphabetical so the generated SQL is stable for tests/logs.
func BuildOrderBy ¶
func BuildRowPolicy ¶
func BuildRowPolicy(expression string, claims *tenant.AuthClaims, paramOffset int) (string, []any, error)
BuildRowPolicy takes a row_policy expression (e.g. "user_id = $auth.id") and replaces each $auth.id, $auth.email and $auth.role with a `?` placeholder, returning the values in the order they appear. paramOffset is unused for SQLite (positional `?`) but kept in the signature for API parity.
func BuildSelect ¶
func BuildUpdate ¶
func BuildUpdate(tableName string, data map[string]any, whereSql string, whereArgs []any) (string, []any)
BuildUpdate returns SQL and args for an UPDATE. SQLite does not support RETURNING portably here, so callers fetch updated rows separately via the same WHERE.
Args order: SET values first (textual order: alphabetical column order), then WHERE values.
func BuildWhere ¶
func BuildWhere(where map[string]any, table *tenant.SchemaTable, paramOffset int) (string, []any, error)
BuildWhere validates columns against the schema and returns parameterized SQLite SQL. All placeholders use `?`; the caller appends args in the order returned. paramOffset is accepted for API compatibility with the multi-segment builders (cursor / row_policy / pagination append more args after) but is unused — SQLite uses positional placeholders, so only args order matters.
func NormalizeRow ¶
NormalizeRow converts SQLite-driver raw types to JSON-friendly values. time.Time values are converted to loc (defaults to UTC when nil). modernc.org/sqlite returns datetimes as time.Time directly when columns are declared TIMESTAMP/DATETIME, and as strings otherwise — those cases are handled by the row scanner in scan.go before reaching here.
func QueryMaps ¶ added in v0.4.0
func QueryMaps(ctx context.Context, q tenant.Querier, loc *time.Location, stmt string, args ...any) ([]map[string]any, error)
QueryMaps runs a query and reads all its rows; with UPDATE/DELETE ... RETURNING * they are exactly the rows the statement changed.
func QuoteIdent ¶ added in v0.1.1
QuoteIdent quotes a table or column name for SQLite. Embedded double quotes are doubled, so the result is always a single identifier. Never use Go's %q for this: its backslash escapes mean nothing to SQLite.
func ResolveIncludes ¶
func ScanAllRowsToMaps ¶
ScanAllRowsToMaps reads every row from a *sql.Rows result set, returning []map[colname]value. Driver-returned []byte values that look like UTF-8 strings are converted to string. time.Time values pass through.
Types ¶
type Cursor ¶
type Cursor struct {
Column string `json:"col"`
Value any `json:"val"`
Direction string `json:"dir"`
}
func DecodeCursor ¶
type IncludeAuthorizer ¶ added in v0.1.1
type IncludeAuthorizer func(table *tenant.SchemaTable) (policySQL string, policyArgs []any, err error)
IncludeAuthorizer decides whether a related table may be included. It returns the extra WHERE fragment (e.g. the table's row policy) to apply, or an error when the caller may not read the table.