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

objection-db-errors

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objection-db-errors

db-errors plugin for objection.js

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
decreased by-12.13%
Maintainers
1
Weekly downloads
 
Created
Source

db-errors plugin for objection

This plugin maps database errors using the db-errors library. By default objection throws whatever the database client throws. The default errors are usually difficult to reason with. This plugin along with the db-errors library try to provide more manageable errors.

Every error class found in require('db-errors') can also be found in require('objection-db-errors'). See db-errors for detailed documentation.

Error handling is something that should not need a plugin. The goal is to eventually merge this into objection core if people find this plugin useful.

Example usage

const { Model } = require('objection');
const { DBErrors } = require('objection-db-errors');

// Usually you want to map each model class's errors. Easiest way to do this
// is to create a common superclass for all your models.
class BaseModel extends DBErrors(Model) {

}

module.exports = {
  BaseModel
};
const { BaseModel } = require('./BaseModel')

class Person extends BaseModel {
  static get tableName() {
    return 'Person';
  }
}

module.exports = {
  Person
};
const { UniqueViolationError } = require('objection-db-errors');

async function something() {
  await Person.query().insert({ id: 1 });

  try {
    // Try to insert a model with an existing primary key.
    await Person.query().insert({ id: 1 });
  } catch (err) {
    console.log(err instanceof UniqueViolationError); // true
  }
}

FAQs

Package last updated on 18 Nov 2019

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