Open necramirez opened 9 years ago
Waterline ORM can be used without Sails, we will amend the documentation to clarify it.
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);
});
});
});
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?
The package description says:
I'm wondering if using Waterline ORM without Sails is the minimum I need, or if Sails is really required.