Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

DeVoresyah ArEst
DeVoresyah ArEst

Posted on

     

Using UUID in AdonisJS v5

Just want to share simple tips how to using UUID in AdonisJS v5. This will help you to define a migration file when using uuid data type and give the default value for it. So, you will no need to use@beforeCreate() on model file.

Before creating the column, you need to create extension ofuuid-ossp first by using this query:

this.db.rawQuery('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";').knexQuery
Enter fullscreen modeExit fullscreen mode

Next, define the uuid column and give default value:

table.uuid('id', { primaryKey: true }).defaultTo(this.db.rawQuery('uuid_generate_v4()').knexQuery)
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Nothing impossible with Javascript~!
  • Location
    Indonesia
  • Work
    Frontend Engineer at Vore Corporation
  • Joined

More fromDeVoresyah ArEst

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp