ORM Overview

Multi-database ORM with PostgreSQL, MySQL, and SQLite.

1 min readEdit this page

Connect

import { createConnection } from '@restjs/orm'
 
const db = await createConnection({
  driver: 'postgres',
  url:    process.env.DATABASE_URL
})

Supported databases

DriverPackage
PostgreSQLpg
MySQLmysql2
SQLitebetter-sqlite3

SQLite for development

const db = await createConnection({
  driver: 'sqlite', filename: './dev.db'
})

Transactions

await db.getDriver().transaction(async (trx) => {
  await trx.query('INSERT INTO users (name) VALUES ($1)', ['Tariq'])
  await trx.query('INSERT INTO profiles (user_id) VALUES ($1)', [1])
})

Note

Database drivers are peer dependencies. Install the one you need.