1.0.4 • Published 7 years ago

@composa/bookshelf-dates v1.0.4

Weekly downloads
1
License
UNLICENSE
Repository
github
Last release
7 years ago

Build Status codecov

bookshelf-dates

Automatically converts SQL dates to JavaScript Date objects.

const user = await User.where({ id: 1 }).fetch();
user.get('dateSubscribed') === new Date('1.1.2017') // true

Installation

Install via npm:

npm install --save @composa/bookshelf-dates

Install via Yarn:

yarn add @composa/bookshelf-dates

Usage

Register the plugin:

import Bookshelf from 'bookshelf';
import bookshelf-dates from '@composa/bookshelf-dates';
import Knex from 'knex';
import knexfile from './knexfile';

const knex = Knex(knexfile);
const bookshelf = Bookshelf(knex);

bookshelf.plugin(dates, { fields: ['dateCreated', 'dateDeleted'] });

Enable it on your models:

const User = bookshelf.Model.extend({
    tableName: 'users',
    convertDates: true
});

You can also define local settings:

const User = bookshelf.Model.extend({
    tableName: 'users',
    convertDates: ['dateSubscribed']
});

Testing

git clone git@github.com:composa/bookshelf-dates.git
cd bookshelf-dates && yarn install && yarn test
1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago