Documentation
¶
Index ¶
- func Delete(t *schema.Table, q query.Query, d dialect.Dialect, withReturning bool) (string, []any, error)
- func Insert(t *schema.Table, rows []map[string]any, d dialect.Dialect, withReturning bool) (string, []any, error)
- func Select(q query.Query, t *schema.Table, lookup SchemaLookup, d dialect.Dialect, ...) (string, []any, []string, error)
- func Update(t *schema.Table, set map[string]any, q query.Query, d dialect.Dialect, ...) (string, []any, error)
- type FilterError
- type SchemaLookup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete( t *schema.Table, q query.Query, d dialect.Dialect, withReturning bool, ) (string, []any, error)
Delete compiles a DELETE into a SQL statement and bound args.
q.Filter feeds the WHERE clause; a nil Filter omits WHERE entirely. The HTTP layer must reject unfiltered DELETE requests (PostgREST returns 400 on unfiltered writes) — Delete itself is filter-agnostic so other callers can opt into table-wide deletes.
withReturning appends "RETURNING *" when the dialect supports it.
func Insert ¶
func Insert( t *schema.Table, rows []map[string]any, d dialect.Dialect, withReturning bool, ) (string, []any, error)
Insert compiles an INSERT into a SQL statement and bound args.
Every row in rows must share the same set of keys. Allowing missing keys would silently NULL-fill columns in a bulk insert and surprise callers, so the builder rejects rows with mismatched key sets.
Column names are validated against the table's column set. The builder does not pre-screen generated / identity columns; if the caller supplies a value the database will surface the appropriate error.
withReturning appends "RETURNING *" when the dialect supports it. Dialects without RETURNING (e.g., MySQL) ignore the flag; callers that need the inserted rows there must run a follow-up SELECT or reject the request.
func Select ¶
func Select( q query.Query, t *schema.Table, lookup SchemaLookup, d dialect.Dialect, defaultLimit, maxLimit int, ) (string, []any, []string, error)
Select compiles a parsed Query into a SELECT statement, bound args, and the list of result-column aliases that carry embedded JSON payloads. The caller should keep those alias columns as raw JSON (e.g. json.RawMessage); `any`-typed unmarshal coerces numbers to float64 and loses BIGINT precision, defeating the JSON_AGG / JSON_OBJECT round-trip.
Identifiers in select / filter / order are validated against the table. lookup resolves embed targets and may be nil only when q.Select has no embed. limit is clamped to [1, maxLimit]; nil falls back to defaultLimit. defaultLimit and maxLimit must be positive with defaultLimit ≤ maxLimit.
func Update ¶
func Update( t *schema.Table, set map[string]any, q query.Query, d dialect.Dialect, withReturning bool, ) (string, []any, error)
Update compiles an UPDATE into a SQL statement and bound args.
set holds the columns to update; column names are validated against the table. q.Filter feeds the WHERE clause: a nil Filter omits WHERE entirely so the statement would touch every row. The HTTP layer must reject unfiltered PATCH requests (PostgREST returns 400 on unfiltered writes) — Update itself is filter-agnostic so other callers (e.g., admin tooling) can opt into bulk updates.
withReturning appends "RETURNING *" when the dialect supports it.
Types ¶
type FilterError ¶
type FilterError struct {
Err error
}
FilterError marks a builder failure that originated from the WHERE clause (unknown column in a filter, malformed predicate, etc.). HTTP handlers can route this to "invalid-query" responses so query-parameter mistakes don't get misreported as body errors. Non-FilterError build failures relate to the SET/body and map to "invalid-body".
func (*FilterError) Error ¶
func (e *FilterError) Error() string
func (*FilterError) Unwrap ¶
func (e *FilterError) Unwrap() error