[[oktatas:web:adonisjs|< AdonisJS]] ====== AdonisJS - Lucid ====== * **Szerző:** Sallai András * Copyright (c) 2025, Sallai András * Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] * Web: https://szit.hu ===== A Lucidról ===== A Lucid egy ORM, ami alapból elérhető az AdonisJS-ben. Leírások: * https://lucid.adonisjs.com/docs/introduction ===== Telepítés ===== node ace add @adonisjs/lucid ===== Modell létrehozása ===== node ace make:model Emplyoee import { DateTime } from 'luxon' import { BaseModel, column } from '@adonisjs/lucid/orm' export default class Employee extends BaseModel { @column({ isPrimary: true }) declare id: number @column() declare name: string @column() declare city: string @column() declare salary: number @column.dateTime({ autoCreate: true }) declare createdAt: DateTime @column.dateTime({ autoCreate: true, autoUpdate: true }) declare updatedAt: DateTime } ===== Migrációs fájl létrehozása ===== node ace make:migration users Példa migrációs fájl: import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { protected tableName = 'employees' async up() { this.schema.createTable(this.tableName, (table) => { table.increments('id') table.string('name').notNullable() table.string('city').nullable() table.double('salary').nullable() table.timestamp('created_at') table.timestamp('updated_at') }) } async down() { this.schema.dropTable(this.tableName) } } A migráció futtatása: node ace migration:run