Skip to content

LouisJULIEN/kysely-basic-plugins

Repository files navigation

Kysely Plugins


This repo contains the source code of two basic Kysely plugins:

  • auto-updated-at: automatically updates a column (e.g. "updated_at) each time an update is made on a row
  • soft-delete: .selectFrom(...) and updateTable(...) ignore rows whose deletion column (e.g. "deleted_at") is not NULL

Questions about the usage

See FAQ.MD

Installation

Copy the files whose names ends with .plugin.ts and paste it into you source code. You can then import it as follows:

import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
import { Pool } from "pg";

import type { DB } from "./db";
import { AutoUpdatedAt } from "./plugins/auto-updated-at.plugin";
import { SoftDelete } from "./plugins/soft-deletion.plugin";

const ignoredTables = [];

export const db = new Kysely<DB>({
  dialect: new PostgresDialect({
    pool: new Pool({
      connectionString: XXXXXX,
    }),
  }),
  plugins: [
    new CamelCasePlugin(),
    new SoftDelete({ ignoredTables, updatedAtColumnName: "my_updated_at" }),
    new AutoUpdatedAt({ ignoredTables, deletedAtColumnName: "terminated_at" }),
  ],
});

Run the tests & build

Set up

You need Node.js, npm and Postgres installed

psql -c "CREATE DATABASE kysely_plugin;"
npm i
npm run migrate:latest

Run the tests

npm run test

Build

npm run build

Contributors

victormachado-ada-tech who published a good first version of a soft delete plugin in an issue

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published