Skip to content

Commit

Permalink
fix(kysely): whitelist compile mehod from proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ecyrbe authored and gcanti committed Jul 29, 2024
1 parent 9749805 commit cf12931
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/sql-kysely/src/internal/kysely.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const makeWithSql = <DB>(config: KyselyConfig) =>
const selectPrototype = Object.getPrototypeOf(db.selectFrom("" as any))
patch(selectPrototype)

return effectifyWithSql(db, client, ["withTransaction"])
return effectifyWithSql(db, client, ["withTransaction", "compile"])
})

/**
Expand Down
33 changes: 32 additions & 1 deletion packages/sql-kysely/test/Sqlite.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Schema } from "@effect/schema"
import { SqlResolver } from "@effect/sql"
import * as SqliteKysely from "@effect/sql-kysely/Sqlite"
import * as Sqlite from "@effect/sql-sqlite-node"
import { assert, describe, it } from "@effect/vitest"
import { Config, Context, Effect, Exit, Layer } from "effect"
import { Config, Context, Effect, Exit, Layer, Option } from "effect"
import type { Generated } from "kysely"

export interface User {
Expand Down Expand Up @@ -48,4 +50,33 @@ describe("SqliteKysely", () => {
const selected = yield* db.selectFrom("users").selectAll()
assert.deepStrictEqual(selected, [])
}).pipe(Effect.provide(KyselyLive)))

it.effect("select with resolver", () =>
Effect.gen(function*(_) {
const db = yield* SqliteDB

yield* db.schema
.createTable("users")
.addColumn("id", "integer", (c) => c.primaryKey().autoIncrement())
.addColumn("name", "text", (c) => c.notNull())

yield* db.insertInto("users").values({ name: "Alice" })
yield* db.insertInto("users").values({ name: "Bob" })
yield* db.insertInto("users").values({ name: "Charlie" })

const GetUserById = yield* SqlResolver.findById("GetUserById", {
Id: Schema.Number,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultId: (data) => data.id,
execute: (ids) => db.selectFrom("users").where("id", "in", ids).selectAll()
})

const todoIds = [1, 2, 3].map((_) => GetUserById.execute(_))
const result = yield* Effect.all(todoIds, { batching: true })
assert.deepStrictEqual(result, [
Option.some({ id: 1, name: "Alice" }),
Option.some({ id: 2, name: "Bob" }),
Option.some({ id: 3, name: "Charlie" })
])
}).pipe(Effect.provide(KyselyLive)))
})

0 comments on commit cf12931

Please sign in to comment.