
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(...)andupdateTable(...)ignore rows whose deletion column (e.g. "deleted_at") is notNULL
See FAQ.MD
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" }),
],
});You need Node.js, npm and Postgres installed
psql -c "CREATE DATABASE kysely_plugin;"
npm i
npm run migrate:latestnpm run testnpm run buildvictormachado-ada-tech who published a good first version of a soft delete plugin in an issue