Giter Club home page Giter Club logo

postgres-adapter's People

Contributors

1602 avatar bhuisgen avatar bmatcuk avatar bradfordh avatar dbryand avatar eduard-ishmukhametov avatar harish2704 avatar ivanrodriguezfernandez avatar jinze avatar martinell avatar quilime avatar radzikowski avatar roryf avatar scottnonnenberg avatar scttnlsn avatar sdrdis avatar wangfei0001 avatar

Stargazers

 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

postgres-adapter's Issues

Error: global leak detected: changes

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.

  1. PostgresDataAccessor.Functional "before all" hook:
    Error: global leak detected: changes
    at Runner.checkGlobals (/Users/henry/src/heroapp-TeenyURL/test/node_modules/mocha/lib/runner.js:169:21)
    at Runner. (/Users/henry/src/heroapp-TeenyURL/test/node_modules/mocha/lib/runner.js:59:44)
    at Runner.EventEmitter.emit (events.js:96:17)
    at Runner.hook (/Users/henry/src/heroapp-TeenyURL/test/node_modules/mocha/lib/runner.js:240:12)
    at Hook.Runnable.run (/Users/henry/src/heroapp-TeenyURL/test/node_modules/mocha/lib/runnable.js:215:5)
    at next (/Users/henry/src/heroapp-TeenyURL/test/node_modules/mocha/lib/runner.js:235:10)
    at Runner.hook (/Users/henry/src/heroapp-TeenyURL/test/node_modules/mocha/lib/runner.js:246:5)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

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);
    }
};

};

fields I use custom name aren't inserted into database

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.

Indexes Using columns not quoted

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!

Don't send null to database?

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.

Native bindings with node-postgres

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

Type boolean !== bool

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;

TypeError: Cannot call method 'forEach' of undefined

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!

database table is emptied when i push my code

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.

Process doesn't finishing after any query

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();

Primary key error

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.

Sql injection prevention

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.

Table not created on first run

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.

autoupdate() not creating tables on first run?

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.

TypeError: Cannot read property 'constructor' of undefined

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

Improve error handling for failed connections

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.

Timing Issues

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);

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.