Giter Site home page Giter Site logo

objection-guid's Introduction

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

npm i objection-guid

Yarn

yarn add objection-guid

Usage

Generate guid

// Import the plugin.
const guid = require('objection-guid')();
const Model = require('objection').Model;

// Mixin the plugin.
class Item extends guid(Model) {
  static get tableName() {
    return 'Item';
  }
}

const item = await Item.query().insert({
  name: 'foo'
});

console.log(item.id);
// 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:

const guid = require('objection-guid')({
  field: 'foo',
  generateGuid: () => 'bar'
});

Tests

Run the tests from the root directory:

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.

objection-guid's People

Contributors

joaonice avatar kratos-42 avatar misablaha avatar nunorafaelrocha avatar rivertam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

objection-guid's Issues

Model extension should be anonymous

Hi!

First of all, thank you for building this plugin for objection. Having a collection of good quality plugins such as this one for the most common problems will do a lot of good for the objection ecosystem.

Objection changed its best practices regarding the name of the extending class returned from the mixin function. The class should not have a name. The reason for this change is explained in this issue.

Please consider updating your plugin to follow the updated practices.

TypeScript types declaration file

This npm package needs a TypeScript types declaration file so that developers who enjoy writing with TS can use it with this package and have a better development experience. Would you like me to write one?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.