项目作者: seegno

项目描述 :
Automatic guid for Objection.js
高级语言: JavaScript
项目地址: git://github.com/seegno/objection-guid.git
创建时间: 2017-07-05T17:08:06Z
项目社区:https://github.com/seegno/objection-guid

开源协议:

下载


Automatic guid for Objection.js

npm
node
Build Status
Coverage Status

This plugin adds an automatic guid to your Objection.js models using the uuid package for guid generation.

Installation

NPM

  1. npm i objection-guid

Yarn

  1. yarn add objection-guid

Usage

Generate guid

  1. // Import the plugin.
  2. const guid = require('objection-guid')();
  3. const Model = require('objection').Model;
  4. // Mixin the plugin.
  5. class Item extends guid(Model) {
  6. static get tableName() {
  7. return 'Item';
  8. }
  9. }
  10. const item = await Item.query().insert({
  11. name: 'foo'
  12. });
  13. console.log(item.id);
  14. // bbbe64b0-61a3-11e7-879a-67bb027591aa

Custom values

If your model already has a value for the configured field, the value is not overwritten.

Options

field: Overrides the default field name of the generated guid. (Default: id)

generateGuid: Overrides the default function that generates a guid. This function can be a promise. (Default: generates UUIDs v4)

These options can be provided when instantiating the plugin:

  1. const guid = require('objection-guid')({
  2. field: 'foo',
  3. generateGuid: () => 'bar'
  4. });

Tests

Run the tests from the root directory:

  1. npm test

You can find Jest documentation here.

Contributing & Development

Contributing

Found a bug or want to suggest something? Take a look first on the current and closed issues. If it is something new, please submit an issue.

Develop

It will be awesome if you can help us evolve objection-guid. Want to help?

  1. Fork it.
  2. npm install.
  3. Hack away.
  4. Run the tests: npm test.
  5. Create a Pull Request.