plugin-slonik

A plugin to allow Fluse fixtures to interact with Slonik.

Install#

yarn add -D fluse-plugin-slonik slonik @types/slonik
tip

This plugin requires slonik to be installed as well.

Example#

import { fluse } from "fluse";
import { createPool, sql } from "slonik";
import slonikPlugin from "fluse-plugin-slonik";
const pool = createPool("postgres://");
const { fixture, scenario } = fluse({
plugins: {
slonik: slonikPlugin({ pool }),
},
});
const userFixture = fixture<User>({
async create({ slonik }) {
const result = await slonik.query<User>(
sql`INSERT INTO users ("user_name") VALUES ('bob') RETURNING *`
);
return result.rows[0];
},
});

API Reference#

The slonik api will become available on the context and a runtime option as you use this plugin.

Signature#

slonikPlugin(options?: {
pool: DatabasePoolType;
transaction?: boolean;
}) => Plugin
  • pool (required): The slonik connection pool,
  • transaction (optional): Run in a single transaction, rolling back if something fails,