sqlfx-kysely
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published
import { Config, Effect } from "effect";
import { Database, createAdaptor } from "sqlfx-kysely/dist/bun";

interface Tables {
	users: { id: number };
}

const DBAdaptor = createAdaptor<Tables>();

const db: Effect.Effect<Database<Tables>, never, void> = Effect.gen(function* (_) {
	const { query } = yield* _(DBAdaptor.tag);
	query((db) => db.selectFrom("users"));
});


const layer = DBAdaptor.makeLayer(
	Config.succeed({
		filename: ":memory:"
	})
);

db.pipe(Effect.provide(layer));

Defining a table

import { Schema } from "@effect/schema";
import { GeneratedAlways, Insertable, Selectable, Updateable } from "kysely";

// User
const Base = Schema.struct({
	firstName: Schema.string,
	lastName: Schema.string,
});

export interface Table extends Schema.Schema.To<typeof Base> {
	id: GeneratedAlways<number>;
}

export type SelectSchema = Selectable<Table>;
export const SelectSchema: Schema.Schema<SelectSchema> = Base.pipe(
	Schema.extend(
		Schema.struct({
			id: Schema.number
		})
	)
);

export type InsertSchema = Insertable<Table>;
export const InsertSchema: Schema.Schema<InsertSchema> = Base;

export type UpdateSchema = Updateable<Table>;
export const UpdateSchema: Schema.Schema<UpdateSchema> = Base.pipe(
	Schema.partial
);

Readme

Keywords

Package Sidebar

Install

npm i sqlfx-kysely

Weekly Downloads

92

Version

0.0.11

License

MIT

Unpacked Size

339 kB

Total Files

56

Last publish

Collaborators

  • kellyjesse881