/** * @since 1.0.0 */ import type { Reactivity } from "@effect/experimental/Reactivity" import type { Tag } from "effect/Context" import * as Context from "effect/Context" import type { Effect } from "effect/Effect" import type { ReadonlyMailbox } from "effect/Mailbox" import type { ReadonlyRecord } from "effect/Record" import type { CloseableScope, Scope } from "effect/Scope" import type { Stream } from "effect/Stream" import type { NoInfer } from "effect/Types" import * as internal from "./internal/client.js" import type { Connection } from "./SqlConnection.js" import type { SqlError } from "./SqlError.js" import type { Compiler, Constructor } from "./Statement.js" /** * @category type ids * @since 1.0.0 */ export const TypeId: unique symbol = internal.TypeId /** * @category type ids * @since 1.0.0 */ export type TypeId = typeof TypeId /** * @category models * @since 1.0.0 */ export interface SqlClient extends Constructor { readonly [TypeId]: TypeId /** * Copy of the client for safeql etc. */ readonly safe: this /** * Copy of the client without transformations. */ readonly withoutTransforms: () => this readonly reserve: Effect /** * With the given effect, ensure all sql queries are run in a transaction. */ readonly withTransaction: ( self: Effect ) => Effect /** * Use the Reactivity service from @effect/experimental to create a reactive * query. */ readonly reactive: ( keys: ReadonlyArray | ReadonlyRecord>, effect: Effect ) => Stream /** * Use the Reactivity service from @effect/experimental to create a reactive * query. */ readonly reactiveMailbox: ( keys: ReadonlyArray | ReadonlyRecord>, effect: Effect ) => Effect, never, R | Scope> } /** * @category models * @since 1.0.0 */ export const SqlClient: Tag = internal.clientTag /** * @category models * @since 1.0.0 */ export namespace SqlClient { /** * @category models * @since 1.0.0 */ export interface MakeOptions { readonly acquirer: Connection.Acquirer readonly compiler: Compiler readonly transactionAcquirer?: Connection.Acquirer readonly spanAttributes: ReadonlyArray readonly beginTransaction?: string | undefined readonly rollback?: string | undefined readonly commit?: string | undefined readonly savepoint?: ((name: string) => string) | undefined readonly rollbackSavepoint?: ((name: string) => string) | undefined readonly transformRows?: ((row: ReadonlyArray) => ReadonlyArray) | undefined readonly reactiveMailbox?: ( keys: ReadonlyArray | ReadonlyRecord>, effect: Effect ) => Effect, never, R | Scope> } } /** * @category constructors * @since 1.0.0 */ export const make: (options: SqlClient.MakeOptions) => Effect = internal.make /** * @since 1.0.0 * @category transactions */ export const makeWithTransaction: ( options: { readonly transactionTag: Tag readonly spanAttributes: ReadonlyArray readonly acquireConnection: Effect readonly begin: (conn: NoInfer) => Effect readonly savepoint: (conn: NoInfer, id: number) => Effect readonly commit: (conn: NoInfer) => Effect readonly rollback: (conn: NoInfer) => Effect readonly rollbackSavepoint: (conn: NoInfer, id: number) => Effect } ) => (effect: Effect) => Effect = internal.makeWithTransaction /** * @since 1.0.0 */ export interface TransactionConnection { readonly _: unique symbol } /** * @since 1.0.0 */ export const TransactionConnection: Tag = internal.TransactionConnection /** * @since 1.0.0 */ export class SafeIntegers extends Context.Reference()("@effect/sql/SqlClient/SafeIntegers", { defaultValue: () => false }) {}