@effect/sql
Advanced tools
+4
-4
| { | ||
| "name": "@effect/sql", | ||
| "version": "0.6.2", | ||
| "version": "0.6.3", | ||
| "description": "A SQL toolkit for Effect", | ||
@@ -16,5 +16,5 @@ "license": "MIT", | ||
| "peerDependencies": { | ||
| "@effect/platform": "^0.60.2", | ||
| "@effect/schema": "^0.69.2", | ||
| "effect": "^3.5.8" | ||
| "@effect/platform": "^0.60.3", | ||
| "@effect/schema": "^0.69.3", | ||
| "effect": "^3.5.9" | ||
| }, | ||
@@ -21,0 +21,0 @@ "publishConfig": { |
+72
-80
@@ -9,20 +9,18 @@ # Effect SQL | ||
| import { Config, Effect, Struct, pipe } from "effect" | ||
| import * as Sql from "@effect/sql" | ||
| import * as Pg from "@effect/sql-pg" | ||
| import { PgClient } from "@effect/sql-pg" | ||
| import { SqlClient } from "@effect/sql" | ||
| const SqlLive = Pg.client.layer({ | ||
| const SqlLive = PgClient.layer({ | ||
| database: Config.succeed("effect_pg_dev") | ||
| }) | ||
| const program = Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| const program = Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
| const people = yield* _( | ||
| sql<{ | ||
| readonly id: number | ||
| readonly name: string | ||
| }>`SELECT id, name FROM people` | ||
| ) | ||
| const people = yield* sql<{ | ||
| readonly id: number | ||
| readonly name: string | ||
| }>`SELECT id, name FROM people` | ||
| yield* _(Effect.log(`Got ${people.length} results!`)) | ||
| yield* Effect.log(`Got ${people.length} results!`) | ||
| }) | ||
@@ -43,5 +41,5 @@ | ||
| import { Config } from "effect" | ||
| import * as Pg from "@sqlfx/pg" | ||
| import { PgClient } from "@sqlfx/pg" | ||
| const SqlLive = Pg.makeLayer({ | ||
| const SqlLive = PgClient.makeLayer({ | ||
| database: Config.succeed("effect_pg_dev") | ||
@@ -55,5 +53,5 @@ }) | ||
| import { Config } from "effect" | ||
| import * as Pg from "@effect/sql-pg" | ||
| import { PgClient } from "@effect/sql-pg" | ||
| const SqlLive = Pg.client.layer({ | ||
| const SqlLive = PgClient.layer({ | ||
| database: Config.succeed("effect_pg_dev") | ||
@@ -69,7 +67,7 @@ }) | ||
| import { Config } from "effect" | ||
| import * as Pg from "@effect/sql-pg" | ||
| import { PgMigrator } from "@effect/sql-pg" | ||
| const MigratorLive = Layer.provide( | ||
| Pg.migrator.layer({ | ||
| loader: Pg.migrator.fromFileSystem( | ||
| PgMigrator.layer({ | ||
| loader: PgMigrator.fromFileSystem( | ||
| fileURLToPath(new URL("migrations", import.meta.url)) | ||
@@ -87,11 +85,11 @@ ), | ||
| - `sql.resolver` -> `Sql.resolver.ordered` | ||
| - `sql.resolverVoid` -> `Sql.resolver.void` | ||
| - `sql.resolverId` -> `Sql.resolver.findById` | ||
| - `sql.resolverIdMany` -> `Sql.resolver.grouped` | ||
| - `sql.resolver` -> `SqlResolver.ordered` | ||
| - `sql.resolverVoid` -> `SqlResolver.void` | ||
| - `sql.resolverId` -> `SqlResolver.findById` | ||
| - `sql.resolverIdMany` -> `SqlResolver.grouped` | ||
| - `sql.resolverSingle*` has been removed in favour of using the `effect/Cache` module with the schema apis | ||
| - `sql.schema` -> `Sql.schema.findAll` | ||
| - `sql.schemaSingle` -> `Sql.schema.single` | ||
| - `sql.schemaSingleOption` -> `Sql.schema.findOne` | ||
| - `sql.schemaVoid` -> `Sql.schema.void` | ||
| - `sql.schema` -> `SqlSchema.findAll` | ||
| - `sql.schemaSingle` -> `SqlSchema.single` | ||
| - `sql.schemaSingleOption` -> `SqlSchema.findOne` | ||
| - `sql.schemaVoid` -> `SqlSchema.void` | ||
@@ -106,4 +104,4 @@ #### The array helper has moved | ||
| import { Effect, pipe } from "effect" | ||
| import * as Schema from "@effect/schema/Schema" | ||
| import * as Sql from "@effect/sql" | ||
| import { Schema } from "@effect/schema" | ||
| import { SqlClient } from "@effect/sql" | ||
@@ -121,7 +119,6 @@ class Person extends Schema.Class<Person>("Person")({ | ||
| export const makePersonService = Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| export const makePersonService = Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
| const InsertPerson = yield* _( | ||
| Sql.resolver.ordered("InsertPerson", { | ||
| const InsertPerson = yield* SqlResolver.ordered("InsertPerson", { | ||
| Request: InsertPersonSchema, | ||
@@ -136,3 +133,3 @@ Result: Person, | ||
| }) | ||
| ) | ||
| const insert = InsertPerson.execute | ||
@@ -148,4 +145,4 @@ | ||
| import { Effect, pipe } from "effect" | ||
| import * as Schema from "@effect/schema/Schema" | ||
| import * as Sql from "@effect/sql" | ||
| import { Schema } from "@effect/schema" | ||
| import { SqlResolver, SqlClient } from "@effect/sql" | ||
@@ -159,13 +156,11 @@ class Person extends Schema.Class<Person>("Person")({ | ||
| export const makePersonService = Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| export const makePersonService = Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
| const GetById = yield* _( | ||
| Sql.resolver.findById("GetPersonById", { | ||
| Id: Schema.Number, | ||
| Result: Person, | ||
| ResultId: (_) => _.id, | ||
| execute: (ids) => sql`SELECT * FROM people WHERE ${sql.in("id", ids)}` | ||
| }) | ||
| ) | ||
| const GetById = yield* SqlResolver.findById("GetPersonById", { | ||
| Id: Schema.Number, | ||
| Result: Person, | ||
| ResultId: (_) => _.id, | ||
| execute: (ids) => sql`SELECT * FROM people WHERE ${sql.in("id", ids)}` | ||
| }) | ||
@@ -185,7 +180,7 @@ const getById = (id: number) => | ||
| import { Effect } from "effect" | ||
| import * as Sql from "@effect/sql" | ||
| import { SqlClient } from "@effect/sql" | ||
| export const make = (limit: number) => | ||
| Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
@@ -201,3 +196,3 @@ const statement = sql`SELECT * FROM people LIMIT ${limit}` | ||
| import { Effect } from "effect" | ||
| import * as Sql from "@effect/sql" | ||
| import { SqlClient } from "@effect/sql" | ||
@@ -207,4 +202,4 @@ const table = "people" | ||
| export const make = (limit: number) => | ||
| Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
@@ -219,4 +214,4 @@ const statement = sql`SELECT * FROM ${sql(table)} LIMIT ${limit}` | ||
| ```ts | ||
| import * as Effect from "effect/Effect" | ||
| import * as Sql from "@effect/sql" | ||
| import { Effect } from "effect" | ||
| import { SqlClient } from "@effect/sql" | ||
@@ -227,4 +222,4 @@ type OrderBy = "id" | "created_at" | "updated_at" | ||
| export const make = (orderBy: OrderBy, sortOrder: SortOrder) => | ||
| Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
@@ -242,7 +237,7 @@ const statement = sql`SELECT * FROM people ORDER BY ${sql(orderBy)} ${sql.unsafe(sortOrder)}` | ||
| import { Effect } from "effect" | ||
| import * as Sql from "@effect/sql" | ||
| import { SqlClient } from "@effect/sql" | ||
| export const make = (names: string[], cursor: string) => | ||
| Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
@@ -261,7 +256,7 @@ const statement = sql`SELECT * FROM people WHERE ${sql.and([ | ||
| import { Effect } from "effect" | ||
| import * as Sql from "@effect/sql" | ||
| import { SqlClient } from "@effect/sql" | ||
| export const make = (names: string[], cursor: Date) => | ||
| Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
@@ -280,7 +275,7 @@ const statement = sql`SELECT * FROM people WHERE ${sql.or([ | ||
| import { Effect } from "effect" | ||
| import * as Sql from "@effect/sql" | ||
| import { SqlClient } from "@effect/sql" | ||
| export const make = (names: string[], afterCursor: Date, beforeCursor: Date) => | ||
| Effect.gen(function* (_) { | ||
| const sql = yield* _(Sql.client.Client) | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient | ||
@@ -307,6 +302,6 @@ const statement = sql`SELECT * FROM people WHERE ${sql.or([ | ||
| import { Effect } from "effect" | ||
| import * as Sql from "@effect/sql" | ||
| import { SqlClient } from "@effect/sql" | ||
| export default Effect.flatMap( | ||
| Sql.client.Client, | ||
| SqlClient.SqlClient, | ||
| (sql) => sql` | ||
@@ -330,23 +325,20 @@ CREATE TABLE users ( | ||
| import { NodeContext, NodeRuntime } from "@effect/platform-node" | ||
| import * as Sql from "@effect/sql" | ||
| import * as Pg from "@effect/sql-pg" | ||
| import { PgClient, PgMigrator } from "@effect/sql-pg" | ||
| import { fileURLToPath } from "node:url" | ||
| const program = Effect.gen(function* (_) { | ||
| const program = Effect.gen(function* () { | ||
| // ... | ||
| }) | ||
| const SqlLive = Pg.client.layer({ | ||
| const SqlLive = PgClient.layer({ | ||
| database: Config.succeed("example_database") | ||
| }) | ||
| const MigratorLive = Pg.migrator | ||
| .layer({ | ||
| loader: Sql.migrator.fromFileSystem( | ||
| fileURLToPath(new URL("migrations", import.meta.url)) | ||
| ), | ||
| // Where to put the `_schema.sql` file | ||
| schemaDirectory: "src/migrations" | ||
| }) | ||
| .pipe(Layer.provide(SqlLive)) | ||
| const MigratorLive = PgMigrator.layer({ | ||
| loader: PgMigrator.fromFileSystem( | ||
| fileURLToPath(new URL("migrations", import.meta.url)) | ||
| ), | ||
| // Where to put the `_schema.sql` file | ||
| schemaDirectory: "src/migrations" | ||
| }).pipe(Layer.provide(SqlLive)) | ||
@@ -353,0 +345,0 @@ const EnvLive = Layer.mergeAll(SqlLive, MigratorLive).pipe( |
395049
-0.01%331
-2.36%