jugglingdb / postgres-adapter Goto Github PK
View Code? Open in Web Editor NEWPostgreSQL adapter for JugglingDB
PostgreSQL adapter for JugglingDB
Title says it all. I saw that jugglingdb recently came back to life, does that apply to the adapters as well?
I'm consistently getting errors like:
{ [error: relation "table_name" does not exist]
length: 97,
name: 'error',
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'namespace.c',
line: '407',
routine: 'RangeVarGetRelidExtended' }
when trying to run autoupdate()
. It appears the code will only attempt to run ALTER TABLE
statements, there is no initial CREATE TABLE
if it does not already exist.
Is this correct? Am I missing something or is this initial migration not implemented yet?
Testing against PostgreSQL 9.2, can post config if that's relevant.
Testing my code with mocha and it complains 'changes' is leaking. This comes from function PG.prototype.isActual definition. changing the line to 'var changes = []' test pass.
PG.prototype.isActual = function(cb) {
var self = this;
var wait = 0;
changes = [];
Object.keys(this._models).forEach(function (model) {
wait += 1;
getTableStatus.call(self, model, function(err, fields){
changes = changes.concat(getPendingChanges.call(self, model, fields));
done(err, changes);
});
});
function done(err, fields) {
if (err) {
console.log(err);
}
if (--wait === 0 && cb) {
var actual = (changes.length === 0);
cb(null, actual);
}
};
};
db.define('foo', {
content: { type: JSON }
})
The JSON column is not properly stringified when use Model.create
hi there,
i love the current library, but i am having a small issue with it.
whenever i push my code to heroku, the table is emptied, i suspect the schema is being dropped and recreated.
I am starting to use this module. Before, I was using the pg driver directly and I was able to prevent sql injection attacks by using placeholders in the queries and passing the parameters to the driver. Wen I started using jugglingdb I realized now I am able to inject sql code into the queries.
Following instructions for npm install:
...
"dependencies": {
"jugglingdb": "0.2.x",
"jugglingdb-postgres": "latest"
},
...
}
npm ERR! Error: No compatible version found: jugglingdb@'=0.2.0-'
Currently only the following stack trace is printed when the connection fails
{projectBasePath}/node_modules/jugglingdb-postgres/lib/postgres.js:419
data.forEach(function(field){
^
TypeError: Cannot read property 'forEach' of undefined
at decoratedCallback ({projectBasePath}/node_modules/jugglingdb-postgres/lib/postgres.js:419:13)
at {projectBasePath}/node_modules/jugglingdb-postgres/lib/postgres.js:64:20
at {projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/pool.js:75:25
at {projectBasePath}/node_modules/jugglingdb-postgres/node_modules/generic-pool/lib/generic-pool.js:274:11
at {projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/pool.js:27:26
at null.<anonymous> ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/client.js:181:5)
at emitOne (events.js:77:13)/
at emit (events.js:169:7)
at Socket.<anonymous> ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:59:10)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at emitErrorNT (net.js:1269:8)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
At that point in the code (postgres.js:419
) an error
object is available and should be used to convey errors to the user.
Same goes if the connection is suddenly broken it will print the following error and crash the app:
events.js:141
throw er; // Unhandled 'error' event
^
error: terminating connection due to administrator command
at Connection.parseE ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:534:11)
at Connection.parseMessage ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:361:17)
at Socket.<anonymous> ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:105:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:536:20)
I suggest providing a more stable way of dealing with errors, such as a number of connection retries followed by a graceful error message if the retries fail.
If you have a case-sensitive model attribute and create a mutli-column index like this:
var User = schema.define('User', {
userId: {
type: Number
},
messageId: {
type: Number
}
}, {
indexes: {
indexPrimary: {
columns: 'userId,messageId',
type: 'btree'
}
}
});
The constructed sql doesn't wrap the column names for the btree's Using context:
CREATE INDEX "indexPrimary" ON "User" USING btree (userId,messageId)
This will result in something like "Cannot find column 'userid'" failure.
Workaround (manually adding the quotes inline):
indexPrimary: {
columns: '"userId","messageId"',
type: 'btree'
}
I am guessing that this should be handled in the library itself, as it does this for single columns perfectly.
Thanks for the hard work!
In autoupdate function, fileds are checked for the type ...
And boolean !== bool so it is always trigering
ALTER TABLE "User" ALTER COLUMN "active" TYPE boolean;
I could able to connect to postgres with postgres-adapter, but how do i map
these configured models in schema.js in under /app/models directory?
Please suggest.
Note : I am using mongodb as primary database and trying to use postgres too in my application.
bigserial
in particular would be very useful to me for larger values.
Other useful types:
uuid
bigint
smallint
Please do an npm publish of the project so that I can make use of the "include" functionality. Thanks!
My question is probably not postgres-adapter specific, but here goes: How can I make sure that null values don't get sent to my database? When the model property does not contain a value I want the SQL DB handle this via either DEFAULT VALUE or returning an error that the NOT NULL-able columns value is missing. Is this possible? Or should I go about this by defining default values in my JS models?
Thank you for your time.
When I use custom field name, the fields are not inserted. Such like:
var User = schema.define('User', {
lastLogin: { name: 'last_login', type: Date }
});
In lib/postgres.js
:
PG.prototype.toFields = function (model, data, forCreate) {
var fields = [];
var props = this._models[model].properties;
if(forCreate){
var columns = [];
Object.keys(data).forEach(function (key) {
if (props[key]) { // I think problem is here!!
if (key === 'id') return;
columns.push('"' + key + '"');
fields.push(this.toDatabase(props[key], data[key]));
}
}.bind(this));
return '(' + columns.join(',') + ') VALUES ('+fields.join(',')+')';
}else{
Object.keys(data).forEach(function (key) {
if (props[key]) {
fields.push('"' + key + '" = ' + this.toDatabase(props[key], data[key]));
}
}.bind(this));
return fields.join(',');
}
};
In above function, props
is:
{
lastLogin: { name: 'last_login', type: [Function: Date] }
}
and Object.keys(data)
is [ 'last_login' ]
. So. props[key]
is false
and ignore the fields I use custom name.
I'm not sure this is handle in whether jugglingdb or postgres-adapter.
i have noticed that my app started to exit with this exeption ..
i have fihured out that if in shema i dont have a default value ... and i don't pass it in object i get this error...
i have fixed all the defalt values in shema file ... but some times i still get this ..
i will try to debug more ... but it only happens on some rare occasion
/node_modules/jugglingdb-postgres/lib/postgres.js:166
if (val.constructor.name === 'Object') {
^
TypeError: Cannot read property 'constructor' of undefined
Hello,
I tried to run my project with the native bindings and it was crashing. I saw that the supported version of node-postgres is 0.7.2. I tested it updated to the version 0.11.2 and everything worked for me. Is it possible to update the version or there is a reason to stick to the current one? It would be great, also, if the module offers some configuration options to switch from the javascript bindings to the native ones.
Thanks
Hello, i tried to start node but got error:
/var/www/html/calendar/node_modules/jugglingdb-postgres/lib/postgres.js:419
data.forEach(function(field){
^
TypeError: Cannot call method 'forEach' of undefined
at decoratedCallback (/var/www/html/calendar/node_modules/jugglingdb-postgres/lib/postgres.js:419:14)
at /var/www/html/calendar/node_modules/jugglingdb-postgres/lib/postgres.js:64:20
at /var/www/html/calendar/node_modules/jugglingdb-postgres/node_modules/pg/lib/pool.js:75:25
at /var/www/html/calendar/node_modules/jugglingdb-postgres/node_modules/generic-pool/lib/generic-pool.js:274:11
at /var/www/html/calendar/node_modules/jugglingdb-postgres/node_modules/pg/lib/pool.js:27:26
at null.<anonymous> (/var/www/html/calendar/node_modules/jugglingdb-postgres/node_modules/pg/lib/client.js:181:5)
at emit (events.js:95:17)
at Socket.<anonymous> (/var/www/html/calendar/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:109:12)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:529:21)
I think trouble to connect database?
"store": {
// You won't want to use the memory store in production, or your install
// registrations will be forgotten any time your app restarts. Here
// we tell atlassian-connect-express to use the PostgreSQL backend for the default
// JugglingDB adapter.
"type": "postgres",
// Again, a PaaS host like Heroku will probably provide the db connection
// URL to you through the environment, so we tell atlassian-connect-express to use that value.
"url": "postgres://localhost:5432/nodejs_calendar"
},
I use node version 0.10.42 on Centos 6 64bit.
Linux CentOS-68-64-minimal 2.6.32-642.6.1.el6.x86_64 #1 SMP Wed Oct 5 00:36:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
And when i do npm install i haven't got any errors.
Thanks!
This commit
1602/jugglingdb@a5f0ab7
breaks completely postgres adapter.
Working on a fix...
I'm getting the following error:
{ [error: relation "User" does not exist]
name: 'error',
length: 95,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '13',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'parse_relation.c',
line: '873',
routine: 'parserOpenTable' }
When I try to create the following table (it does not exist in the DB yet):
var User = database.define({'User', {
username: {type: String}
});
I read this bug had been fixed, so maybe there's something I'm missing.
Versions
$ grep version ./node_modules/jugglingdb-postgres/package.json
"version": "0.0.6",
$ grep version ./node_modules/jugglingdb/package.json
"version": "0.2.14",
Test file
// test
var jdb = require('jugglingdb');
// db
var pg = new jdb.Schema(require('jugglingdb-postgres'), {database: 'test', username: 'test', host: 'localhost'});
pg.log = console.log.bind(console);
// models
var Topic = pg.define('Topic', { title: String });
// sync
pg.automigrate();
Not sure where in the stack this issue originates at (be it jugglingdb-postgres or pg), but the following code
var User = require('./models.js').User,
user = new User();
user.save();
throws
events.js:72
throw er; // Unhandled 'error' event
^
error: invalid frontend message type 0
at p.parseE (./node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:497:11)
at p.parseMessage (./node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:357:17)
at Socket.<anonymous> (./node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:84:22)
at Socket.EventEmitter.emit (events.js:117:20)
at Socket.<anonymous> (_stream_readable.js:736:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
when run via node test.js
. Delaying the call to user.save
by a little bit works around this:
var User = require('./models.js').User,
user = new User();
setTimeout(function() { user.save(); }, 1000);
Primary key error:
{ [error: column "id" does not exist]
length: 90,
name: 'error',
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '32',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'parse_expr.c',
line: '768',
routine: 'transformColumnRef' }
My code:
var Schema = require('jugglingdb').Schema;
var schema = new Schema('postgres', {
database: 'crm',
username: 'ja',
host: '10.0.0.1'
});
var Case = schema.define('cases.basic', {
case_id: { type: Number },
market_id: { type: Number }
});
Case.all(function(r) {
console.log(r);
});
I didn't find any way to define column as promary_key and it's not readed properly from database. In this example case_id is primary key.
How can I do ORDER BY "created_at" desc nulls last
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.