1.0.14 • Published 9 months ago

@hamta/adonis-orm v1.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

adonis-hashids

Hashids for AdonisJS 5

gh-workflow-image typescript-image npm-image license-image download-image

This package generates YouTube-like IDs for AdonisJS Lucid models using the hashids.js package. hashids.js is small JavaScript library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.

Prerequisites

  • Adonis Lucid to be installed and configured

  • The db table must have a column named hashid of type string and it must be nullable.

Installation

npm i @fcoded/adonis-hashids or  yarn add @fcoded/adonis-hashids

Configuration

node ace configure @fcoded/adonis-hashids

The configuration file is in config/hashids.ts. The default salt will be the project name, the default minLength is 12 and it uses the default alphabet from the hashids.js package.

Using the Hashids Mixin

Apply the mixin on the model you.

import { compose } from '@ioc:Adonis/Core/Helpers'
import { column, BaseModel } from '@ioc:Adonis/Lucid/Orm'
import { LucidHashIds } from '@ioc:Adonis/Adons/LucidHashIds'

export default class User extends compose(BaseModel, LucidHashIds){

}

The mixin will update the hashid column after the recorded is created using the afterCreate Model hook

Also, if you are using Route model binding package, the routeLookupKey will be set to the hashid by default.

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

10 months ago