SqlSchema.ts
SqlSchema.ts overview
Section titled “SqlSchema.ts overview”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.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”findAll
Section titled “findAll”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
Signature
declare const findAll: <Req extends Schema.Constraint, Res extends Schema.Constraint, E, R>(options: { readonly Request: Req readonly Result: Res readonly execute: (request: Req["Encoded"]) => Effect.Effect<ReadonlyArray<unknown>, E, R>}) => ( request: Req["Type"]) => Effect.Effect<Array<Res["Type"]>, E | Schema.SchemaError, Req["EncodingServices"] | Res["DecodingServices"] | R>Since v4.0.0
findNonEmpty
Section titled “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 const findNonEmpty: <Req extends Schema.Constraint, Res extends Schema.Constraint, E, R>(options: { readonly Request: Req readonly Result: Res readonly execute: (request: Req["Encoded"]) => Effect.Effect<ReadonlyArray<unknown>, E, R>}) => ( request: Req["Type"]) => Effect.Effect< Arr.NonEmptyArray<Res["Type"]>, E | Schema.SchemaError | Cause.NoSuchElementError, Req["EncodingServices"] | Res["DecodingServices"] | R>Since v4.0.0
findOne
Section titled “findOne”Builds a query function that encodes the request, decodes the first result
row, and fails with NoSuchElementError when no rows are returned.
Signature
declare const findOne: <Req extends Schema.Constraint, Res extends Schema.Constraint, E, R>(options: { readonly Request: Req readonly Result: Res readonly execute: (request: Req["Encoded"]) => Effect.Effect<ReadonlyArray<unknown>, E, R>}) => ( request: Req["Type"]) => Effect.Effect< Res["Type"], E | Schema.SchemaError | Cause.NoSuchElementError, R | Req["EncodingServices"] | Res["DecodingServices"]>Since v4.0.0
findOneOption
Section titled “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 const findOneOption: <Req extends Schema.Constraint, Res extends Schema.Constraint, E, R>(options: { readonly Request: Req readonly Result: Res readonly execute: (request: Req["Encoded"]) => Effect.Effect<ReadonlyArray<unknown>, E, R>}) => ( request: Req["Type"]) => Effect.Effect< Option.Option<Res["Type"]>, E | Schema.SchemaError, R | Req["EncodingServices"] | Res["DecodingServices"]>Since v4.0.0
Runs a sql query with a request schema and discard the result.
Signature
declare const void: <Req extends Schema.Constraint, E, R>(options: { readonly Request: Req; readonly execute: (request: Req["Encoded"]) => Effect.Effect<unknown, E, R>; }) => (request: Req["Type"]) => Effect.Effect<void, E | Schema.SchemaError, R | Req["EncodingServices"]>Since v4.0.0