Database

ORM Overview

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

1 min readDocumentationEdit this page

Connect#

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

Supported databases#

DriverPackage
PostgreSQLpg
MySQLmysql2
SQLitebetter-sqlite3

SQLite for development#

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

Transactions#

typescript
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.

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY