@evryg/effect-integresql
v0.0.1
Published
An Effect based client of the integresql tool used for creating isolated postgresql databases used in integration tests
Readme
@evryg/effect-integresql
Effect client for IntegreSQL, used to create isolated PostgreSQL databases for integration tests.
Installation • Usage • Testcontainers • License
Installation
npm install --save-dev @evryg/effect-integresql effecteffect is the only required peer dependency.
This package supports Node.js 18 and newer.
Glob matching support used by templateIdFromFiles(...) is built in through this package's internal fast-glob dependency. You do not need to install glob or fast-glob yourself.
This package is only the client. You still need a running IntegreSQL server connected to PostgreSQL. To install IntegreSQL itself, follow the official setup instructions: https://github.com/allaboutapps/integresql#install
Usage
import { Effect } from "effect"
import {
getConnection,
templateIdFromFiles,
type DatabaseConfiguration
} from "@evryg/effect-integresql"
const getSingleUseAdminDatabase = getConnection({
templateId: templateIdFromFiles(["**/*.sql"]),
initializeTemplate: (connection) => runMigrations(connection),
integreSQLAPIUrl: "http://localhost:5000"
})
test("Create user", () =>
pipe(
getSingleUseAdminDatabase,
Effect.flatMap((connection) =>
pipe(
Effect.gen(function*() {
const params = {email: "[email protected]"}
const result = yield* UserGateway.create(params)
expect(user).toStrictEqual<typeof result>({email: "[email protected]"})
}),
Effect.provide(pipe(
LivePostgresUserGateway,
Layer.provide(makePgLayer(connection))
))
)
),
Effect.runPromise
))
templateIdFromFiles(...) hashes your migration files so template changes track schema changes.
initializeTemplate(...) runs once for a given template id to prepare the template database.
Each call to getConnection(...) returns connection details for a fresh isolated test database cloned from that template.
Testcontainers
For a complete Vitest + Testcontainers setup, see:
License
MIT. See ./LICENSE.
