How can I define a unique field in lucid orm in adonisjs latest app?

20 views Asked by At

import { DateTime } from 'luxon' import { withAuthFinder } from '@adonisjs/auth' import hash from '@adonisjs/core/services/hash' import { compose } from '@adonisjs/core/helpers' import { BaseModel, column } from '@adonisjs/lucid/orm'

const AuthFinder = withAuthFinder(() => hash.use('scrypt'), { uids: ['phone'], passwordColumnName: 'password', })

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

@column() declare fullName: string | null

@column() declare email: string

// I want to create this phone field unique and give it length to max=10 and min 10 @column() declare phone: string

@column() declare password: string

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

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

I have tried like this but I'm getting error.

@column({ ** unique: true** }) declare phone: string

and I modify it a little bit to see if it works but it didn't

@column( ** unique: true** ) declare phone: string

0

There are 0 answers