loopbackio / loopback-connector-cassandra

Cassandra connector for the LoopBack framework.
Other
13 stars 22 forks source link

Unable to use your connector ( model configuration issue, automigration gives NaN 'cassandra' ) #53

Closed Orxcle-xx closed 6 years ago

Orxcle-xx commented 7 years ago

Hi guys,

I am trying to use integrate loopback-connector-cassandra with no success.

First issue I stumbled upon is how models should be configured. According to the documentation, they should be configured similar to this:

zipCodes = db.define('zipCodes', {
  state: String,
  zipCode: Number,
  });

But loopback configures them totally differently! The common structure is:

{
  "name": "AppUser",
  "base": "User",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

How exactly they should be configured?

I also tried to create tables in Cassandra using this code ( I tried both methods autoupdate & automigrate ):

var server = require('./server');
var ds = server.dataSources.cassandra;
var models = []; // will be aplied to all models
ds.autoupdate(models, function(er) {
  if (er) throw er;
  console.log('Loopback tables [' - models - '] created in ', ds.adapter.name);
  ds.disconnect();
});

My datasource name is "cassandra". However, code just prints:

NaN 'cassandra'

Do you have any basic example of fully configured Loopback project with cassandra datastore? I believe it will help a lot.

Thank you in advance.

Best,

kjdelisle commented 7 years ago

Sorry, this one slipped through the cracks. Technically, in the body of the model definition, you'll want to add your properties in the properties collection.

So, in the above example you've given, it would look like this:

{
  "name": "AppUser",
  "base": "User",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "state": {
      "type": "string"
    },
    "zipCode": {
      "type": "number"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}
stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.