Skip to content

Installation

This guide will show you how you can get started with no-orm as quickly as possible.

Since no-orm is a code-generator tool, we install no-orm as a dev-dependency.

Terminal window
npm install -D no-orm-cli

You should be prompted to install some peer-dependencies.

Terminal window
npm install slonik zod postgres-range postgres-interval

So yes, if you are using no-orm, you also must use Slonik and Zod.

Terminal window
npx no-orm init

This creates a config file for no-orm. Point this to your local database.

See the full config file reference here. (TODO: Add link).

Apply the following schema to your database:

penguins.sql
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!

Terminal window
npx no-orm generate --config-path no-orm.config.ts

And voilà! You can now easily create, read, update and delete a penguin in your Typescript server!

table.ts
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"];
// ...