Dung (Donny) Nguyen

Senior Software Engineer

Lucid ORM

Lucid in Adonis.js is the official Object-Relational Mapper (ORM) built on top of Knex.js, designed to provide an active record-style data modeling and querying layer for SQL databases within Adonis.js applications.123

Core Features

Supported Databases

Example Model (TypeScript)

import { DateTime } from 'luxon'
import { BaseModel, column } from '@adonisjs/lucid/orm'

export default class User extends BaseModel {
  @column({ isPrimary: true })
  declare id: number

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

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

Usage and Customization

Installation

To install Lucid in your AdonisJS project:

npm i @adonisjs/lucid

After installing, the setup process will help configure database connections and essential dependencies like Luxon for date handling.5

Lucid ORM is an integral and powerful part of the Adonis.js ecosystem, focusing on developer productivity, maintainability, and a rich Active Record pattern for database management.2135 678910

  1. https://docs.adonisjs.com/guides/database/lucid  2 3

  2. https://lucid.adonisjs.com/docs/models  2 3 4

  3. https://lucid.adonisjs.com  2 3 4 5

  4. https://www.youtube.com/watch?v=xmPwSqKA8ho  2 3

  5. https://adocasts.com/lessons/introducing-installing-and-configuring-lucid-orm  2 3 4

  6. https://news.ycombinator.com/item?id=35256796 

  7. https://stackoverflow.com/questions/55077645/adonis-lucid-orm-not-returning-data 

  8. https://www.youtube.com/watch?v=w4fMW8UJ310 

  9. https://github.com/francisjed/adonis-lucid 

  10. https://adocasts.com/lessons/lets-learn-adonis-5-setting-up-lucid