No description
Find a file
2025-06-05 13:04:01 -07:00
.changeset Commit new patch version 2025-05-31 20:51:17 -07:00
src Add more complex tests 2025-06-01 22:18:36 -07:00
.gitignore Add to .gitignore 2025-04-13 02:35:59 -04:00
CHANGELOG.md Update 2025-06-05 13:04:01 -07:00
LICENSE Create LICENSE 2025-04-13 02:29:12 -04:00
package.json Update 2025-06-05 13:04:01 -07:00
pnpm-lock.yaml Update 2025-06-05 13:04:01 -07:00
README.md Add generator params example to README 2025-06-01 22:30:04 -07:00
tsconfig.json Add tsconfig.json 2025-04-12 19:30:34 -04:00
tsup.config.ts Add tsup config 2025-04-12 19:23:44 -04:00

kysely-firebird

Kysely Dialect and Type Generator for Firebird DB. Utilizes node-firebird for database connectivity.

Implementation guided by kysely-oracledb.

Installation

npm install kysely node-firebird kysely-firebird

Important

This project currently uses node-firebird version 1.2.x, which isn't yet released on npm. Install the library with npm install hgourvest/node-firebird#e1c4dd9 to avoid any issues.

Usage

Firebird DB Dialect

To use the Dialect with Kysely, you must pass in a node-firebird Pool to the FirebirdDialect constructor.

Type-casting to unknown is required to satisfy TypeScript.

// See the section below for more information on generating types.
import type { DB } from "./types.ts";

import Firebird from "node-firebird";
import { Kysely } from "kysely";
import { FirebirdDialect, FirebirdPool } from "kysely-firebird";

const options = {
  host: "host",
  port: 3050,
  database: "/path/to/database.fdb",
  user: "SYSDBA",
  password: "pass",
};

const pool = Firebird.pool(5, options);

const db = new Kysely<DB>({
  dialect: new FirebirdDialect({
    pool: pool as unknown as FirebirdPool,
  }),
});

You can now use the db instance to query your Firebird database.

const users = await db
  .from("USERS")
  .select("ID", "NAME")
  .where("ID", "=", 1)
  .execute();

Dialect Configuration

The dialect can be configured with the following options:

Option Type Description Required
pool oracledb.Pool node-firebird DB connection pool. Yes
logger Logger Logger instance for debug messages. No

Type Generation

Kysely requires you to define the types for your database schema. You can define these manually, or generate them using the generate function:

import Firebird from "node-firebird";
import { generate } from "kysely-firebird";

const options = {
  host: "host",
  port: 3050,
  database: "/path/to/database.fdb",
  user: "SYSDBA",
  password: "pass",
};

const pool = Firebird.pool(5, options);

await generate({
  pool: pool as unknown as FirebirdPool,
  generator: {
    // optional generator options
  },
});

This will generate a types file with the following structure:

import type { Insertable, Selectable, Updateable } from "kysely";

interface UserTable {
  id: number;
  name: string;
}

export type User = Selectable<UserTable>;
export type NewUser = Insertable<UserTable>;
export type UserUpdate = Updateable<UserTable>;

export interface DB {
  user: UserTable;
}

Generator Configuration

The generator can be configured with the same options as the dialect, plus the following options:

Option Type Description Required
type "tables" | "views" | "all" Type of generation to perform. No
tables string[] List of tables to scope type generation. No
checkDiff boolean Check for differences against existing types before generating. No
metadata boolean Generate table metadata json file. No
filePath string File path to write the types to. No
metadataFilePath string File path to write the metadata (json) to. No
prettierOptions prettier.Options Prettier options for formatting. No