Installation
This guide will show you how you can get started with no-orm as quickly as possible.
Installation
Section titled “Installation”Since no-orm is a code-generator tool, we install no-orm as a dev-dependency.
npm install -D no-orm-cliYou should be prompted to install some peer-dependencies.
npm install slonik zod postgres-range postgres-intervalSo yes, if you are using no-orm, you also must use Slonik and Zod.
Initialise no-orm
Section titled “Initialise no-orm”npx no-orm initThis creates a config file for no-orm. Point this to your local database.
See the full config file reference here. (TODO: Add link).
Your first auto-generated code
Section titled “Your first auto-generated code”Apply the following schema to your database:
CREATE TABLE penguins ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, species TEXT NOT NULL, waddle_speed_kph NUMERIC NOT NULL, favourite_snack TEXT, -- Optional: not all penguins have refined palates. date_of_birth TIMESTAMP WITH TIME ZONE NOT NULL);Run no-orm!
npx no-orm generate --config-path no-orm.config.tsAnd voilà! You can now easily create, read, update and delete a penguin in your Typescript server!
import { z } from "zod";import { type CommonQueryMethods, type ListSqlToken, sql } from "slonik";
export const row = z.object({ id: z.number().brand<"public.penguins.id">(), name: z.string(), species: z.string(), waddle_speed_kph: z.number(), favourite_snack: z.string().nullable(), date_of_birth: z.date(),});
export type Row = z.infer<typeof row>;
export type Id = Row["id"];
// ...