Giter Site home page Giter Site logo

jsonapi-store-relationaldb's Introduction

Coverage Status Build Status npm version Code Climate Dependencies Status

jsonapi-store-relationaldb

โš ๏ธ PLEASE NOTE: Version 4.x releases erroneously created columns for string properties as Sequelize text type. The behaviour in version 5.x has reverted back to creating columns with the Sequelize string type, which is the more adequate type and was the behaviour in versions 3.x and older. The text columns created by version 4.x will need to be manually migrated to string columns.

jsonapi-store-relationaldb is a relational database backed data store for jsonapi-server.

This project conforms to the specification laid out in the jsonapi-server handler documentation.

Supported Databases

  • Postgres
  • MySQL
  • MariaDB

Usage

var RelationalDbStore = require("jsonapi-store-relationaldb");

jsonApi.define({
  resource: "comments",
  handlers: new RelationalDbStore({
    dialect: "mysql",
    dialectOptions: {
      supportBigNumbers: true
    },
    host: "localhost",
    port: 3306,
    database: "jsonapi", // If not provided, defaults to the name of the resource
    username: "root",
    password: null,
    logging: false
  })
});

Note: the logging property controls the logging of the emitted SQL and can either be false (which will mean it will be captured by the internal debugging module under the namespace jsonApi:store:relationaldb:sequelize) or a user provided function (e.g. console.log) to which a string containing the information to be logged will be passed as the first argument.

Alternative Usage - Provide Sequelize instance

If you are already using sequelize or need to have access to the sequelize instance, you may provide an instance to the store to be used instead of having the store create a new instance from the given config.

var RelationalDbStore = require("jsonapi-store-relationaldb");
var Sequelize = require("Sequelize");

var sequelize = new Sequelize("jsonapi", "root", null, {dialect: "mysql"}));

jsonApi.define({
  resource: "comments",
  handlers: new RelationalDbStore({
    sequelize: sequelize
  })
});

Features

  • Search, Find, Create, Delete, Update
  • Efficient lookups via appropriate indexes
  • Filtering happens at the database layer
  • Transactional queries

Getting to Production

Getting this data store to production isn't too bad...

  1. Bring up your relational database stack.
  2. Create the database(s).
  3. Create the database tables. You can call (new RelationalDbStore()).populate() to have this module attempt to create the require tables. If you enable debugging via DEBUG=jsonApi:store:* you'll see the create-table statements - you can target a local database, call populate(), grab the queries, review them and finally run them against your production stack manually.
  4. Deploy your code.
  5. Celebrate.

When deploying schema changes, you'll need to correct your database schema - database migrations are left as an exercise for the user. If your schema are likely to change frequently, maybe consider using a different (less schema-driven) data store.

When changing columns in a production database, a typical approach might be to create a new table that is a clone of the table in production, copy all data from the production table into the new table, run an ALTER-TABLE command on the new table to adjust the columns (this may take a while and will lock the table), then run a RENAME-TABLES to swap the production table out for the new one.

Note: When populating database tables, you can use the force config option to DROP and CREATE tables. This is helpful in development stage, when your data doesn't matter and you want your Tables schemas to change according to the DAOs without having to manually write migrations.

(new RelationalDbStore()).populate({force: true}, () => {
  //tables dropped and created
})

Gotchas

Relational databases don't differentiate between undefined and null values. Joi does differentiate between undefined and null values. Some undefined properties will pass validation, whilst null properties may not. For example, the default articles resource contains a created attribute of type "date" - this won't pass validation with a null value, so the Joi schema will need tweaking.

jsonapi-store-relationaldb's People

Contributors

aledalgrande avatar bjornharrtell avatar championswimmer avatar connormeredith avatar derekryansnider avatar duncanfenning avatar jangxyz avatar jonathonwalz avatar m-bymike avatar oliversalzburg avatar paparomeo avatar pmcnr-hx avatar theninj4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonapi-store-relationaldb's Issues

Inject sequelize connection

Maybe a nice feature to have is to inject an existing Sequelize connection into the store instead of creating two sequelize connection instances.

Column not created using when clause

I've written a schema as follows in which my goal is that the 'itemOrder' array should always have the same length as the items attr / relationship. When I add the 'when' clause, however, the itemOrder column does not get created (using postgres). If I omit the 'when' clause it does get created. Not sure if this is a bug or if I'm not using / understanding the when clause correctly. Thanks for any help you can offer.

jsonApi.define({
    resource: 'itemSets',
    handlers: resourceHandlers.itemSets,
    attributes: {
        title: jsonApi.Joi.string().required(),
        items: jsonApi.Joi.many('items').required(),
        itemOrder: jsonApi.Joi.array().required()
                            .items(jsonApi.Joi.string().uuid())
                            .when('items', {
                                is: jsonApi.Joi.exist(),
                                then: jsonApi.Joi.array().length(jsonApi.Joi.ref('items.length')),
                                otherwise: jsonApi.Joi.array().length(0)
                            })
    }
});

missing "type" and "meta" columns

I am working with a postgreSQL database, I simply tried a Get request on 0.0.0.0/my_table and I get

sequelize:pool connection acquired +3s
  sequelize:sql:pg executing(default) : SELECT count(*) AS "count" FROM "my_table" AS "my_table"; +3s
  sequelize:sql:pg executed(default) : SELECT count(*) AS "count" FROM "my_table" AS "my_table"; +2ms
  sequelize:pool connection released +2ms
  sequelize:pool connection acquired +2ms
  sequelize:sql:pg executing(default) : SELECT "id", "type", "meta", "name", "mobilenumber" FROM "my_table" AS "my_table"; +2ms
  sequelize:pool connection released +2ms
  sequelize:pool connection drain due to process exit +3s
  sequelize:pool connection destroy +1ms
...
...
  jagql:requestCounter 0 GET /my_table +0ms
  jagql:validation:input {"type":"my_table"} +0ms
  jagql:handler:search {"type":"my_table","page":{"offset":0,"limit":50}} [{"status":"500","code":"EUNKNOWN","title":"An unknown error has occured","detail":"Something broke when connecting to the database - column \"meta\" does not exist"},null,null] +0ms
  jagql:errors GET /my_table {"status":"500","code":"EUNKNOWN","title":"An unknown error has occured","detail":"Something broke when connecting to the database - column \"type\" does not exist"} +0ms

However there is no "type", and "meta" column in my_table.

ps: I also tested the jagql module, and I have the missed "meta" issues...

I read the #53 issue ticket, however I don't know if it is fixed.. It is not clear in the ticket ๐Ÿ˜ž ๐Ÿ˜ข

TypeError: Cannot convert undefined or null to object at SqlStore._buildModels

I am using the handler code from the example in the readme and am running into the error below when I run node.

Any ideas on how I can solve this?

/Users/[path to app]/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:104
  var localAttributes = Object.keys(self.resourceConfig.attributes).filter(function(attributeName) {
                               ^

TypeError: Cannot convert undefined or null to object
    at SqlStore._buildModels (/Users/[path to app]/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:104:32)
    at SqlStore.initialise (/Users/[path to app]/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:72:8)
    at Object.jsonApi.define.resourceConfig [as define] (/Users/[path to app]/node_modules/jsonapi-server/lib/jsonApi.js:68:29)
    at Object.<anonymous> (/Users/[path to app]/index.js:29:9)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.runMain (module.js:575:10)
    at run (bootstrap_node.js:352:7)
    at startup (bootstrap_node.js:144:9)
    at bootstrap_node.js:467:3

Enable timestamps and "paranoid" mode

I understand why they are disabled by default, but I would like to enable those options for my models. It seems the option is hardcoded, I think it should be available to the user to select those (and maybe more) options from Sequelize.

Support simple object serialization

The MemoryHandler allows one to use joi.objects as attributes, for example:

position: jsonApi.Joi.object({
  x: jsonApi.Joi.number().required(),
  y: jsonApi.Joi.number().required()
}).required(),

Unfortunately, this explodes when using relationaldb (tested with postgres), which reflects the fact that the 'object' type doesn't seem to be properly handled. Ideally relationaldb would be able to handle simple objects like this in situations where relationals like one, many, ... aren't appropriate or would be overkill.

Creates work even if validation fails; Record not retrievable

Debugging (with handler logging through bunyan):

  jsonApi:requestCounter 3 +39s POST /users
  jsonApi:validation:input {"id":"2f14ceb5-81fd-4b29-ba93-48a87209b0ad","type":"users","name":"jason","email":"[email protected]"} +1ms
[2016-07-17T14:45:01.399Z] TRACE: test-jsonapi-server/3139 on jason-chaletos: Executing (50444f2a-4cd8-4b2a-9f9d-5ded28340b0f): START TRANSACTION;
[2016-07-17T14:45:01.400Z] TRACE: test-jsonapi-server/3139 on jason-chaletos: Executing (50444f2a-4cd8-4b2a-9f9d-5ded28340b0f): SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
[2016-07-17T14:45:01.403Z] TRACE: test-jsonapi-server/3139 on jason-chaletos: Executing (50444f2a-4cd8-4b2a-9f9d-5ded28340b0f): INSERT INTO "users" ("id","type","name","email") VALUES ('2f14ceb5-81fd-4b29-ba93-48a87209b0ad','users','jason','[email protected]') RETURNING *;
[2016-07-17T14:45:01.406Z] TRACE: test-jsonapi-server/3139 on jason-chaletos: Executing (50444f2a-4cd8-4b2a-9f9d-5ded28340b0f): COMMIT;
  jsonApi:handler:create {"type":"users","data":{"attributes":{"name":"jason","email":"[email protected]"},"type":"users"}} +20ms [null,{"id":"2f14ceb5-81fd-4b29-ba93-48a87209b0ad","type":"users","name":"jason","email":"[email protected]"}]
[2016-07-17T14:45:01.413Z] TRACE: test-jsonapi-server/3139 on jason-chaletos: Executing (default): SELECT "id", "type", "meta", "name", "email", "roles" FROM "users" AS "users" WHERE "users"."id" = '2f14ceb5-81fd-4b29-ba93-48a87209b0ad';
  jsonApi:store:relationaldb Produced +7ms {"id":"2f14ceb5-81fd-4b29-ba93-48a87209b0ad","type":"users","name":"jason","email":"[email protected]","roles":null}
  jsonApi:handler:find {"type":"users","data":{"attributes":{"name":"jason","email":"[email protected]"},"type":"users"},"id":"2f14ceb5-81fd-4b29-ba93-48a87209b0ad"} +0ms [null,{"id":"2f14ceb5-81fd-4b29-ba93-48a87209b0ad","type":"users","name":"jason","email":"[email protected]","roles":null}]
  jsonApi:validation:output {"id":"2f14ceb5-81fd-4b29-ba93-48a87209b0ad","type":"users","name":"jason","email":"[email protected]","roles":null} +0ms
  jsonApi:validation:error child "roles" fails because ["roles" must be a string] +2ms {"id":"2f14ceb5-81fd-4b29-ba93-48a87209b0ad","type":"users","name":"jason","email":"[email protected]","roles":null}

The `server.metrics.on('data'):

{ route: 'users/:id',
  verb: 'POST',
  httpCode: 201,
  error: null,
  duration: 30 }

The server never responds with the ID according to Ember Inspector (I'm guessing the data key is empty).

Attempts to query the new ID directly fail as well, which was the reason for #36.

Looking through the docs, I think this should return a 403 Forbidden (http://jsonapi.org/format/#crud-creating-responses-403).

To replicate this issue, this is the Ember.js code (roles is completely missing from the create POST):

      var user = this.get('store').createRecord('user', {
        name: 'jason',
        email: '[email protected]'
      });

On the server:

var server = require('jsonapi-server');
...
server.define({
  resource: 'users',
  handlers: handler2,
  attributes: {
    name: server.Joi.string(),
    email: server.Joi.string(),
    roles: server.Joi.string().allow('')
  }
});

You have an error in your SQL syntax near VIRTUAL

For developer mode, I'm trying to populate a MySQL schema with a very simple resource.

  • latest jsonapi-store-relationaldband jsonapi-server
yarn versions v1.3.2
{ http_parser: '2.7.0',
  node: '8.9.1',
  v8: '6.1.534.47',
  uv: '1.15.0',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  nghttp2: '1.25.0',
  openssl: '1.0.2m',
  icu: '59.1',
  unicode: '9.0',
  cldr: '31.0.1',
  tz: '2017b' }
โœจ  Done in 0.03s.
// project.js
const { define, Joi } = require('jsonapi-server');

module.exports = handlers =>
    define({
        resource: 'projects',
        handlers,
        attributes: {
            name: Joi.string(),
            statusLabelGreen: Joi.string(),
            statusLabelYellow: Joi.string(),
            statusLabelRed: Joi.string(),
            images: Joi.many('images'),
            status: Joi.string()
        }
    });

The populate looks like this:

const Sequelize = require('sequelize');
const sequelize = new Sequelize(
    config.db.schema,
    config.db.username,
    config.db.password,
    config.db
);
const RelationalDbStore = require('jsonapi-store-relationaldb');
const relationalDbStore = new RelationalDbStore({sequelize});
require('./images')(relationalDbStore);
require('./projects')(relationalDbStore);

if (process.env.NODE_ENV === 'development') {
    relationalDbStore.populate({force: true}, function(error) {
        debug('store.populate: %O', error)
    });
}

The error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VIRTUAL, meta VARCHAR(255), name TEXT, statusLabelGreen TEXT, `statusLabel' at line 1'

the SQL:

CREATE TABLE IF NOT EXISTS `database-name.projects` (`id` CHAR(36) BINARY , `type` VIRTUAL, `meta` VARCHAR(255), `name` TEXT, `statusLabelGreen` TEXT, `statusLabelYellow` TEXT, `statusLabelRed` TEXT, `status` TEXT, PRIMARY KEY (`id`)) ENGINE=InnoDB;

The relevant call stack indicates this is happening in https://github.com/holidayextras/jsonapi-store-relationaldb/blob/master/lib/sqlHandler.js#L105

self.baseModel.sync(options).asCallback(cb)

appears as if the Joi schema translation is picking up the type VIRTUAL facet, which it shouldn't be adding to the table.

Any help appreciated! ๐Ÿบ

Support SQLite

SQLite doesn't support nested transactions which this project seems to depend on. The project doesn't announce support for SQLite, but it should technically be possible to support it alongside the other Sequelize supported dialects.

SequelizeDatabaseError: SQLITE_ERROR: cannot start a transaction within a transaction
  at Query.formatError (node_modules/sequelize/lib/dialects/sqlite/query.js:348:14)
  at Statement.afterExecute (node_modules/sequelize/lib/dialects/sqlite/query.js:112:29)
  at Statement.replacement (node_modules/sqlite3/lib/trace.js:20:31)
  at Statement.replacement (node_modules/sqlite3/lib/trace.js:20:31)

Promises are being created but not being returned

Every time breakPromise is being called I get a promise warning:

Warning: a promise was created in a  handler but was not returned from it
    at process._tickDomainCallback (node.js:463:13)
From previous event:
    at Function.each (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/promise.js:21:17)
    at Sequelize.drop (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/sequelize.js:1008:18)
    at Promise.try.then.then.models (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/sequelize.js:941:19)
    at process._tickDomainCallback (node.js:463:13)
    at Function.Module.runMain (module.js:499:11)
From previous event:
    at Promise.then (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/promise.js:21:17)
    at Sequelize.sync (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/sequelize.js:939:6)
    at SqlStore.populate (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:47:31)
    at SqlStore.initialise (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:41:8)
    at Object.jsonApi.define (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-server/lib/jsonApi.js:57:29)
    at Object.<anonymous> (/Users/duncan.fenning/git/hapi/jsonApi/bookings.js:6:9)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Array.forEach (native)
    at module.exports (/Users/duncan.fenning/git/hapi/jsonApi.js:63:6)
    at Object.<anonymous> (/Users/duncan.fenning/git/hapi/server.js:140:24)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

This module with Chain Handlers

We are using this module and it works great on its own:

// sqlHandler.js
const RelationalDbStore = require('@dcp/jsonapi-store-relationaldb');
const Sequelize = require('sequelize');
const dialect = 'postgres';

module.exports = config =>
  new RelationalDbStore({
    dialect,
    sequelize: new Sequelize(config.dbName, config.username, config.password, {
      host: config.host,
      dialect,
      dialectOptions: {
        options: {
          encrypt: true
        },
        sslmode: 'require',
        ssl: config.ssl
      },
      port: config.port || 5432,
      logging: config.logging != undefined ? config.logging : console.log
    })
  });

But now, we are trying to add some before* chain handlers like so:
https://jagql.github.io/pages/project_setup/chain_handlers.html

So, I created a simple duplicateHandler shell like so:

// duplicateHandler.js
const jag = require('@jagql/framework');
const chainHandler = new jag.ChainHandler();

chainHandler.beforeCreate = (request, newResource, callback) => {
  console.log('beforeCreate:request', JSON.stringify(request));
  console.log('beforeCreate:newResource', JSON.stringify(newResource));
  // if (err) {
  //   callback(err);
  // } else {
  callback(null, request, newResource);
  // }
};
module.exports = chainHandler;
// Main file
import { duplicateHandler, sqlHandler } = require('./handlers');
...
const handlers = duplicateHandler.chain(sqlHandler));
jag.define({
   resource: 'things',
   handlers,
   attributes: {
       name: jag.Joi.string().required()
   }
});

Now I get the error "TypeError: handlers.populate is not a function"

Any suggestions?

Multiple resources per database

This might be a stupid question, but I don't understand why each resource aka. table needs to get its own database.

The main reason why I want to use a relational database instead of a simpler store is that I my app is dealing with multiple, related resources. And creating one database per resource is not very practicable.

Security: Update Sequelize.

There is a patch available (not yet targetting) for a high priority vulnerability in the MySQL and PostgreSQL Geo functions.
Please update it in the dependencies.

Calling populate() gets TypeError: Cannot read property 'sync' of undefined

I'm just setting up jsonapi-server to mock our JSON:API, but while I try to populate the DB, I get the following error:

/aniola-cotesco-se/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:105
      self.baseModel.sync(options).asCallback(cb)
                    ^

TypeError: Cannot read property 'sync' of undefined
    at /aniola-cotesco-se/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:105:21
    at /aniola-cotesco-se/node_modules/async/dist/async.js:3853:24
    at replenish (/aniola-cotesco-se/node_modules/async/dist/async.js:946:17)

I kept my resource file very simple and already tried to remove the attributes, but that doesn't make a difference:

jsonApi.define({
  namespace: 'json:api',
  resource: 'settings',
  handlers: dbHandler,
  attributes: {
    title: jsonApi.Joi.string().required()
      .description('The articles title, should be between 8 and 15 words')
      .example('Learning how to use JSON:API'),
    content: jsonApi.Joi.string().required()
      .description('The main body of the article, provided as HTML')
      .example('<p>Paragraph 1. Lovely.</p><hr /><p>The End.</p>'),
    created: jsonApi.Joi.string().regex(/^[12]\d\d\d-[01]\d-[0123]\d$/)
      .description('The date on which the article was created, YYYY-MM-DD')
      .example('2017-05-01'),
    status: jsonApi.Joi.string().default('published')
      .description('The status of the article - draft, ready, published')
      .example('published'),
    views: jsonApi.Joi.number().default(0)
      .description('Number of views for this article')
  }
})

What might it be that I'm not aware of? ๐Ÿค—

Sorry, for asking my question here!

I want to use singular table name where can I customize this parameter?
I know that Sequelize has a parameter tableName but I don't know how to do.

Do you have forum or something for asking technical question?

Sorry and thanks.

Date handling broken

Properties declared in resources as Joi.date() are being persisted by the relationaldb store as strings but not being converted from the Date object that Joi returns, which results in the following error:

Rolling transaction back after error: {"name":"SequelizeValidationError","message":"string violation: birthDate cannot be an array or an object","errors":[{"message":"birthDate cannot be an array or an object","type":"string violation","path":"birthDate","value":"1969-12-31T16:00:00.000Z"}]} +6ms
Executing (917da062-51e8-4231-aec8-68bf5f19466c): ROLLBACK;

Doesn't work with SQLite because "storage" parameter to Sequelize

To work with a SQLite database, Sequelize needs a "storage" parameter but this handler doesn't have that ability so it always defaults to ":memory:".

I suggest the sequelizeArgs (sqlHandler.js line 47) variable needs to be updated to be able to pass the "storage" parameter.

I'd submit a Pull Request but my knowledge of Git is sadly lacking!

Upgrade to Sequelize 4

Hi,

sequelize 4 has been out for a while, any reason why you are not updating? If I delete the sequelize version used by this library and force it to use v4, I get much better error messages.

Columns [meta] and [type] included in mssql query

When connecting to a SQL Server instance, [type] and [meta] columns are ending up in the raw sql query.

"errors": [
{
"status": "500",
"code": "EUNKNOWN",
"title": "An unknown error has occured",
"detail": "Something broke when connecting to the database - Invalid column name 'meta'."
}
]

SELECT [id], [type], [meta], [first_name], [last_name], [phone_number], [middle_name], [title], [suffix], [email_address], [birth_date], [date_created], [date_modified], [address_line1], [address_line2], [address_line3], [address_line4], [city], [state], [postal_code], [country], [clark_region] FROM [workers] AS [workers];

Cannot retrieve database items; Creates work fine

Using dialect: 'postgres'

Simple GET requests like http://localhost:21337/users produces a response with no database records.

Response:

โœ“ (37.0ms) 10:10:38 $ cat ~/Downloads/users 
{"jsonapi":{"version":"1.0"},"meta":{"page":{"offset":0,"limit":50,"total":1}},"links":{"self":"/users"},"data":[],"included":[]}

Server logging (with server.metrics.on('data')):

[2016-07-17T14:13:15.154Z] TRACE: test-jsonapi-server/2410 on jason-chaletos: Executing (default): SELECT "id", "type", "meta", "name", "email", "roles" FROM "users" AS "users" LIMIT 50 OFFSET 0;
{ route: 'users',
  verb: 'GET',
  httpCode: 200,
  error: null,
  duration: 21 }

As the user that the database server is using:

akfusa=# SELECT "id", "type", "meta", "name", "email", "roles" FROM "users" AS "users" WHERE "users"."id" = 'e2f53450-f522-47f0-bf5a-b6a583fe6a09';
                  id                  | type  | meta | name  |    email    | roles 
--------------------------------------+-------+------+-------+-------------+-------
 e2f53450-f522-47f0-bf5a-b6a583fe6a09 | users |      | jason | [email protected] | 
(1 row)

Note: This entry was created using the same server configuration and a POST. The table was previously created using handler.populate()

Lastly, trying to GET an existing id http://localhost:21337/users/e2f53450-f522-47f0-bf5a-b6a583fe6a09 triggers this on my jsonapi-server:

[2016-07-17T14:06:23.853Z] TRACE: test-jsonapi-server/2410 on jason-chaletos: Executing (default): SELECT "id", "type", "meta", "name", "email", "roles" FROM "users" AS "users" WHERE "users"."id" = 'e2f53450-f522-47f0-bf5a-b6a583fe6a09';
{ route: 'users/:id',
  verb: 'GET',
  httpCode: '404',
  error: 'Resource is not valid',
  duration: 5 }

Is this project still being maintained?

I noticed quite a few issues that should be easy to fix. Before I start creating dozens of branches and PR, I'd like to know if there is even a point in doing so.

EventEmitter memory leak on 11+ resources

When instantiating a new RelationalStore for 11 or more resources, you get a node warning:

node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at process.EventEmitter.addListener (events.js:160:15)
    at process.on.process.addListener (node.js:773:26)
    at ConnectionManager (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:45:11)
    at new ConnectionManager (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:12:29)
    at new MysqlDialect (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/dialects/mysql/index.js:12:28)
    at new Sequelize (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/node_modules/sequelize/lib/sequelize.js:203:20)
    at SqlStore.initialise (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-store-relationaldb/lib/sqlHandler.js:35:20)
    at Object.jsonApi.define (/Users/duncan.fenning/git/hapi/node_modules/jsonapi-server/lib/jsonApi.js:57:29)
    at Object.<anonymous> (/Users/duncan.fenning/git/hapi/jsonApi/trips.js:6:9)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Array.forEach (native)
    at module.exports (/Users/duncan.fenning/git/hapi/jsonApi.js:63:6)
    at Object.<anonymous> (/Users/duncan.fenning/git/hapi/server.js:140:24)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Allow relation and table names to be user-defined

I'm trying to integrate jsonapi-server into our stack and attaching our existing data is the issue I am currently focusing on. I'm already somewhat confident that this module will not work for us, but I'm ready to give it a shot.

The biggest issue is sequelize trying to force certain names for relations and tables. How to work around this issue is explained in the legacy tables documentation. This module currently does not provide the means to access these configuration options. I would like to change that.

Is that in-line with the design of this module? Is this already possible and I'm just missing the right options?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.