0.1.5 • Published 7 years ago

knex-generic-errors v0.1.5

Weekly downloads
20
License
MIT
Repository
github
Last release
7 years ago

knex-generic-errors Build Status

A module for knex.js that enables using more detailed "typed" errors instead of plain javascript Error.

Supported knex versions:

  • ^0.10
  • ^0.11
  • ^0.12

Supported dialects:

Installation

$ npm install knex-generic-errors --save-dev

Usage

As Knex actually doesn't have an API for plugins this module has to be used as seen below.

var Knex = require('knex');
var knexGenericErrors = require('knex-generic-errors');

// Wrap Knex initializer
var knex = knexGenericErrors.attach(Knex, function() {
  // Initialize Knex
  return Knex(/* connection configuration */);
});

// Use `knex`
knex.raw('SELECT * FROM')
.catch(Knex.Errors.QueryError, function(err){
	/* eg. log query error */
});

knexGenericErrors.Errors === Knex.Errors; // true
knex.Errors === Knex.Errors; // true

API

knex-generic-errors

      <dt>knexInstanceResolver</dt>
      <dd>
        <span>A function that gets executed internally to receive initialized knex instance.</span>
        <dl>
          <dt>-</dt>
          <dd>-</dd>
        </dl>
      </dd>
    </dl>
  </td>
  <td>
  	<dl>
      <dt>knexInstance</dt>
      <dd>
        An initialized knex instance.
      </dd>
    </dl>
  </td>
  <td>Enables more detailed errors on Knex and knex instance</td>
</tr>
<tr>
  <td><a name="knex-generic-errors-Errors"></a><b>Errors</b></td>
  <td>-</td>
  <td>-</td>
  <td>Property that holds error types. Error types listed under <a href="#errors">Errors</a></td>
</tr>

Errors

Following errors can be accessed through knex-generic-errors property Errors or after attaching to instance from Knex.Errors or knex instance knex.Errors property.

Running Tests

Tests can be runned without any database in place.

$ npm install
$ npm test

Copyright and License

Copyright Kaarel Raspel, 2016

MIT Licence

0.1.5

7 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago