Skip to content

tomi77/node-bookshelf-tastypie

Repository files navigation

bookshelf-tastypie

Django Tastypie models for Bookshelf

Build Status Coverage Status Code Climate dependencies Status devDependencies Status peerDependencies Status Downloads

Table of contents

Installation

NPM

npm install bookshelf-tastypie --save

Yarn

yarn add bookshelf-tastypie

Usage

Load models to registry

require('bookshelf-tastypie')(bookshelf);

or load model/collection

let ApiKey = require('bookshelf-tastypie')(bookshelf).ApiKey;

Available models / collections

Tastypie.ApiKey

ApiKey model

toString() -> string

String representation of api key

generateKey() -> string

Static function to generate unique keys

ApiKey = bookshelf.model('Tastypie.ApiKey')
new_key = ApiKey.generateKey()

Tastypie.ApiKeys

ApiKey collection

Tastypie.ApiAccess

toString() -> string

String representation od api access

Tastypie.ApiAccesses

Testing your project

In beforeAll hook runs knex migrations in order

  • Django
  • Tastypie
  • Your project

All migrations must have own migration table (tableName property).

before(function() {
  knex.migrate.latest({directory: 'node_modules/bookshelf-django/migrations/', tableName: 'knex_migrations_django'})
}).then(function() {
  knex.migrate.latest({directory: 'node_modules/bookshelf-tastypie/migrations/', tableName: 'knex_migrations_tastypie'})
}).then(function() {
  knex.migrate.latest({directory: 'src/migrations/', tableName: 'knex_migrations_my_project'})
})

In afterAll hook runs knex migrations in reverse order

  • Your project
  • Tastypie
  • Django
after(function() {
  knex.migrate.rollback({directory: 'src/migrations/', tableName: 'knex_migrations_my_project'})
}).then(function() {
  knex.migrate.rollback({directory: 'node_modules/bookshelf-tastypie/migrations/', tableName: 'knex_migrations_tastypie'})
}).then(function() {
  knex.migrate.rollback({directory: 'node_modules/bookshelf-django/migrations/', tableName: 'knex_migrations_django'})
})