SqlSchema
Wraps SQL execution callbacks with request encoding and result decoding.
SqlSchema is a small adapter between Effect Schema and SQL statements. Each helper builds a function that accepts the decoded request type used by application code, encodes it before calling execute, and decodes unknown driver rows into the result schema. The helpers cover returning all rows, a non-empty row list, the first row, an optional first row, or discarding the SQL result for side-effect-only statements.
Constructors
Signature
declare function findAll<Req extends Constraint, Res extends Constraint, E, R>(options: {
readonly execute: (request: Req["Encoded"]) => Effect<readonly Array<unknown>, E, R>;
readonly Request: Req;
readonly Result: Res;
}): (request: Req["Type"]) => Effect<Array<Res["Type"]>, SchemaError | E, R | Req["EncodingServices"] | Res["DecodingServices"]>findNonEmpty
Builds a query function that encodes the request, decodes all result rows, and fails with NoSuchElementError when the result set is empty.
When to use
Use when you need to run a query that must return at least one row and treat an empty result as a failure.
See
findAllfor queries where an empty result should return an empty array
Signature
declare function findNonEmpty<Req extends Constraint, Res extends Constraint, E, R>(options: {
readonly execute: (request: Req["Encoded"]) => Effect<readonly Array<unknown>, E, R>;
readonly Request: Req;
readonly Result: Res;
}): (request: Req["Type"]) => Effect<[Res["Type"], ...Array<Res["Type"]>], NoSuchElementError | SchemaError | E, R | Req["EncodingServices"] | Res["DecodingServices"]>Builds a query function that encodes the request, decodes the first result row, and fails with NoSuchElementError when no rows are returned.
Signature
declare function findOne<Req extends Constraint, Res extends Constraint, E, R>(options: {
readonly execute: (request: Req["Encoded"]) => Effect<readonly Array<unknown>, E, R>;
readonly Request: Req;
readonly Result: Res;
}): (request: Req["Type"]) => Effect<Res["Type"], NoSuchElementError | SchemaError | E, R | Req["EncodingServices"] | Res["DecodingServices"]>findOneOption
Builds a query function that encodes the request, decodes the first result row as Option.some, and returns Option.none when no rows are returned.
Signature
declare function findOneOption<Req extends Constraint, Res extends Constraint, E, R>(options: {
readonly execute: (request: Req["Encoded"]) => Effect<readonly Array<unknown>, E, R>;
readonly Request: Req;
readonly Result: Res;
}): (request: Req["Type"]) => Effect<Option<Res["Type"]>, SchemaError | E, R | Req["EncodingServices"] | Res["DecodingServices"]>
Builds a query function that encodes the request and decodes all result rows, allowing an empty result set.
When to use
Use when you need to run a query that may return zero or more rows and represent an empty result as an empty array.
See
findNonEmptyfor queries where an empty result is a failure