0.6.1 • Published 11 months ago

kanel-kysely v0.6.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Kysely extension for Kanel

Generate Kysely types directly from your Postgres database. This packages extends Kanel with some Kysely specific features. Check ./example/.kanelrc.js for how to customize your schema generation.

// @generated
// This file is automatically generated by Kanel. Do not modify manually.

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

/** Identifier type for actor */
export type ActorId = number & { __flavor?: "ActorId" };

/** Represents the table public.actor */
export default interface ActorTable {
  /** Database type: pg_catalog.int4 */
  actor_id: ColumnType<ActorId, ActorId | null, ActorId | null>;

  /** Database type: pg_catalog.varchar */
  first_name: ColumnType<string, string, string | null>;

  /** Database type: pg_catalog.varchar */
  last_name: ColumnType<string, string, string | null>;

  /** Database type: pg_catalog.timestamp */
  last_update: ColumnType<Date, Date | null, Date | null>;
}

export type Actor = Selectable<ActorTable>;

export type NewActor = Insertable<ActorTable>;

export type ActorUpdate = Updateable<ActorTable>;

Assuming you already have Kanel installed, add this with

$ npm i -D kanel-kysely

To use it, add it to your .kanelrc.js file:

const { makeKyselyHook } = require("kanel-kysely");

module.exports = {
  // ... your config here.

  preRenderHooks: [makeKyselyHook()],
};

Note About Branded IDs

Kanel generates some types with extra guards.

/** Identifier type for actor */
export type ActorId = number & { __flavor?: "ActorId" };

{ __flavor?: 'ActorId' } exists at build time and not at runtime. It will prevent you from accidentally passing an incorrect value for the Id.

To pass a string value as primary key or foreign key reference, just add a type assertion for the <table>Id generated type.

In cases such as subqueries, the type assertion will happen automatically.

Usage with CamelCasePlugin

If you use Kysely with CamelCasePlugin then append kyselyCamelCaseHook to preRenderHooks:

const { makeKyselyHook, kyselyCamelCaseHook } = require("kanel-kysely");

module.exports = {
  // ... your config here.

  preRenderHooks: [makeKyselyHook(), kyselyCamelCaseHook],
};

Type Filter

If you're using Kysely for migrations, you might want to filter the types of the migration tables, such as kysely_migration and kysely_migration_lock. The kyselyTypeFilter will do this for you.

  const { kyselyTypeFilter } = require("kanel-kysely");

  module.exports = {
    /// ... your config here.

    typeFilter: kyselyTypeFilter,
  };
0.6.1

11 months ago

0.6.0

1 year ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.2

2 years ago

0.3.3

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago