Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samlaycock/kysely-plugin-prefix
Kysely plugins to automatically prefix tables and indexes
https://github.com/samlaycock/kysely-plugin-prefix
Last synced: 2 months ago
JSON representation
Kysely plugins to automatically prefix tables and indexes
- Host: GitHub
- URL: https://github.com/samlaycock/kysely-plugin-prefix
- Owner: samlaycock
- License: mit
- Created: 2023-11-08T09:01:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-05T18:39:04.000Z (2 months ago)
- Last Synced: 2024-11-05T18:48:11.415Z (2 months ago)
- Language: TypeScript
- Size: 79.1 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-kysely - kysely-plugin-prefix - set of plugins that allow you to prefix table and index names implicitly (Plugins)
README
# Kysely Prefix Plugin
Automatically add prefixes to your table names with
[Kysely](https://kysely.dev/).This is handy for when you have multiple `Kysely` clients connected to the same
database and you want to avoid table and index name/migration collisions.## Install
`npm i kysely kysely-plugin-prefix`
## Usage
### Tables
```ts
import { Kysely, SqliteDialect } from "kysely";
import { TablePrefixPlugin } from "kysely-plugin-prefix";
import Database from "better-sqlite3";interface ExampleDatabase {
users: {
id: number;
name: string;
};
}const db = new Kysely({
dialect: new SqliteDialect({
database: new Database(':memory:'),
}),
plugins: [new TablePrefixPlugin({ prefix: "prefix" })],
});const users = await db.selectFrom("users").selectAll().execute();
```### Indexes
```ts
import { Kysely, SqliteDialect } from "kysely";
import { IndexPrefixPlugin } from "kysely-plugin-prefix";interface ExampleDatabase {
users: {
id: number;
name: string;
};
}const db = new Kysely({
dialect: new SqliteDialect({
database: new Database(':memory:'),
}),
plugins: [new IndexPrefixPlugin({ prefix: "prefix" })],
});const users = await db.schema
.createIndex("idx_users_id")
.on("users")
.columns(["id"])
.compile(); // Index will be named "prefix_idx_users_id"
```## Excludes
You can exclude tables (or indexes) from being prefixed by passing an array of
table/index names to the optional `exclude` option on either plugin.```ts
import { Kysely, SqliteDialect } from "kysely";
import { TablePrefixPlugin } from "kysely-plugin-prefix";
import Database from "better-sqlite3";interface ExampleDatabase {
users: {
id: number;
name: string;
};
posts: {
id: number;
title: string;
};
}const db = new Kysely({
dialect: new SqliteDialect({
database: new Database(':memory:'),
}),
plugins: [new TablePrefixPlugin({ prefix: "prefix", exclude: ["posts"] })],
});const posts = await db.selectFrom("posts").selectAll().execute();
```