Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

objection-guid

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objection-guid

objection-guid

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

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.

Keywords

FAQs

Package last updated on 03 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc