@effit/knex
v0.1.0-alpha.7
Published
Knex integration for the Effit framework.
Downloads
1,167
Readme
@effit/knex
Knex integration for the Effit framework.
Provides a managed Knex Context.Tag (with Effect-aware query logging and a graceful destroy() finalizer) and a cleanDatabase helper for integration tests.
Installation
pnpm add @effit/knex @effit/core effect knex knex-cleanerUsage
EffitKnex.make(configEffect) returns the framework tag with a .Default Layer attached — the Effect can pull config from anywhere in your application layer:
import { Effect } from 'effect';
import { Knex as EffitKnex } from '@effit/knex/Knex.js';
import knexConfig from './knexfile.js';
import { AppConfig } from '#app/_config/AppConfig.js';
export const Knex = EffitKnex.make(
Effect.gen(function* () {
const appConfig = yield* AppConfig;
return knexConfig[appConfig.nodeEnv];
}),
);The resulting Knex.Default Layer propagates whatever the config Effect requires (here AppConfig) — provide it upstream in your container.
In use cases / queries:
const { knex } = yield* Knex;
const rows = yield* Effect.promise(() => knex('evaluations').select('*'));Cleaning a test database
import { cleanDatabase } from '@effit/knex/cleanDatabase.js';
import knexConfig from './knexfile.js';
await cleanDatabase(knexConfig.test);Truncates every non-migration table and closes the connection.
License
MIT © Talysson de Oliveira Cassiano
