Skip to content

Modern ORM for Typescript. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more

Notifications You must be signed in to change notification settings

gideaoms/clark-orm

Repository files navigation

npm version

ClarkORM

If you like this project, please give us a star on Github.

ClarkORM is a Typescript ORM built on top of Lucid ORM (AdonisJS).

Why

AdonisJS is a great framework and it has one of the best ORM. But it works only in its ecosystem. Using ClarkORM you can have all the benefits of Lucid, but in any Node.js project you want.

How it works

ClarkORM is built on top of Lucid ORM and Lucid ORM is built on top of knex. The idea of ClarkORM is let you manage your migrations and seeds with knex the way you already do. But when it comes to Models ClarkORM comes on scene.

Installation

npm install clark-orm @adonisjs/lucid luxon

Usage

Here you can configure your connection like Adonis Lucid

// database.ts
import { defineConfig } from "clark-orm";

export const { BaseModel, Event, Database } = defineConfig({
  connection: "sqlite",
  connections: {
    sqlite: {
      client: "sqlite",
      debug: false,
      useNullAsDefault: true,
      connection: {
        filename: "./db.sqlite",
      },
    },
  },
})
// models/city.ts
import { DateTime } from "luxon";
import { column } from "@adonisjs/lucid/orm";
import { BaseModel } from "../database";

export class CityModel extends BaseModel {
  public static table = "cities";

  @column({ isPrimary: true })
  public id: number;

  @column()
  public name: string;

  @column.dateTime({ autoCreate: true })
  public createdAt: DateTime;

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  public updatedAt: DateTime;
}

You can learn more about the models here.

Extra

To use ClarkORM you need to know at least a little about knex and Lucid

Do you like to learn with examples? We have one here

Remember to add it to your tsconfig.json

"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false

About

Modern ORM for Typescript. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published