0.4.0 • Published 3 days ago

kanel-kysely v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days 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.

0.4.0

3 days ago

0.3.2

5 months ago

0.3.3

3 months ago

0.3.1

5 months ago

0.3.0

5 months ago

0.2.3

6 months ago

0.2.2

6 months ago

0.2.1

7 months ago

0.2.0

9 months ago

0.1.0

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago