Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will sails-db2 work without Sails? #13

Open
necramirez opened this issue Aug 26, 2015 · 3 comments
Open

Will sails-db2 work without Sails? #13

necramirez opened this issue Aug 26, 2015 · 3 comments

Comments

@necramirez
Copy link

The package description says:

IBM DB2 adapter for the Sails framework and Waterline ORM.

I'm wondering if using Waterline ORM without Sails is the minimum I need, or if Sails is really required.

@kmox83
Copy link
Member

kmox83 commented Aug 26, 2015

Waterline ORM can be used without Sails, we will amend the documentation to clarify it.

@dantedubonc
Copy link

I am trying to use sails-db2 with FeathersJs (using the adapter for Waterline), but I have an strange error:

Details: Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token ",id" was found following "ARCHAR(255),complete". Expected tokens may include: "". SQLSTATE=42601

The code that I am using is the exact same code from the example of feathers-waterline (adapted to DB2):

if (!global._babelPolyfill) { require('babel-polyfill'); }

import feathers from 'feathers';
import rest from 'feathers-rest';
import bodyParser from 'body-parser';
import Waterline from 'waterline';
import db2Adapter from 'sails-db2';
import waterline from '../lib';

const ORM = new Waterline();
const config = {
  adapters: {
    'default': db2Adapter,
    mydb2Adapter: db2Adapter
  },
  connections: {
    myDb2Connection: {
      adapter: 'mydb2Adapter',
      host: 'localhost',
      port: 50001,
      user: 'XXXXX',
      password: 'XXXXXX',
      database: 'XXXXX',
      schemaDB2: 'XXXXX'
    }
  },
  defaults: {
    migrate: 'alter'
  }
};
const Todo = Waterline.Collection.extend({
  identity: 'todo',
  schema: true,
  connection: 'myDb2Connection',
  attributes: {
    text: {
      type: 'string',
      required: true
    },

    complete: {
      type: 'boolean'
    }
  }
});

// Create a feathers instance.
const app = feathers()
  // Enable REST services
  .configure(rest())
  // Turn on JSON parser for REST services
  .use(bodyParser.json())
  // Turn on URL-encoded parser for REST services
  .use(bodyParser.urlencoded({ extended: true }));

module.exports = new Promise(function (resolve) {
  ORM.loadCollection(Todo);
  ORM.initialize(config, (error, data) => {
    if (error) {
      console.error(error);
    }

    // Create a Waterline Feathers service with a default page size of 2 items
    // and a maximum size of 4
    app.use('/todos', waterline({
      Model: data.collections.todo,
      paginate: {
        default: 2,
        max: 4
      }
    }));

    app.use(function (error, req, res, next) {
      res.json(error);
    });

    // Start the server
    const server = app.listen(3030);
    server.on('listening', function () {
      console.log('Feathers Todo waterline service running on 127.0.0.1:3030');
      resolve(server);
    });
  });
});

@dantedubonc
Copy link

I have debugged and I have discovered that the issue maybe is related with the SQL dialect used by this plugin. I am using DB2 express and the DDL statement to create the table for this model is the following:

CREATE TABLE todo (text VARCHAR(255),complete ,
  id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,createdAt ,updatedAt )

This statement is not valid for DB2 express, so, I would like to know, Which flavors of DB2 is supporting this plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants