Coder Social home page Coder Social logo

mesa's People

Contributors

sh avatar snd avatar steffenmllr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mesa's Issues

(maybe) for includes add helpful assertions to catch problems early

given link is the object describing the include,
leftTable is original table,
rightTable is the table that is included,
leftRecord is any record selected from the leftTable during the include query,
rightRecord is any record selected from the rightTable during the include query.

  • assert leftRecord[link.left]?
  • assert rightRecord[link.right]?
  • assert that for every rightRecord there exists a leftRecord such that leftRecord[link.left] == rightRecord[link.right]

node-pg requires call to done() method

The latest versions of node-pg require a call to a done method in order to return the connection back in the pool. The previous behaviour was to return the connection automatically into the pool.

Brian explained the changes for the 1.x version in a pull request

Do you have any plans to add this feature?

Adding support for schemas

Would be great if there was support for schemas

CREATE SCHEMA someschema;

CREATE TABLE someschema.users (
    id uuid primary key default uuid_generate_v4(),
    name text,
    email VARCHAR (355) UNIQUE NOT NULL
);
var userTable = mesaWithConnection.table('someschema.users');
userTable.
    .attributes(['email'])
    .insert({
        email: '[email protected]'
    }, function(err, id) {
    });

Returns:

INSERT INTO "someschema.users" ("email") VALUES ($1) RETURNING id

Should return:

INSERT INTO someschema.users ("email") VALUES ($1) RETURNING id

[or]

INSERT INTO "someschema"."users" ("email") VALUES ($1) RETURNING id

Should this be fixed in https://github.com/snd/mesa/blob/master/src/mesa.coffee#L30-L31 or within the mohair._escape or is it possible to be fixed somewhere else?

insert parameters as postges function params

sometimes one needs to insert a value from the app passed through a postgres function

for example

INSERT INTO foo (bar) VALUES (pi()); -- without params
INSERT INTO foo (bar) VALUES (abs($1)); -- with one param
INSERT INTO foo (bar) VALUES (log($1,$2)); -- with n params
INSERT INTO foo (bar) VALUES (log(2,$1)); -- with some postgres values and some app params

Eventually it would be great to nest these arguments and functions

INSERT INTO foo (bar) VALUES (crypt($1, gen_salt('bf', $2)));

Attached functions and hooks don't share mesas state (this).

The new release candidate doesn't seem to bind the state of the current model to it's hooks and attached functions.

var assert = require('assert');
var mesa = require('mesa');

var model = mesa
.beforeInsert(function(data) {
  assert(this.where, 'where should exist.')
  return data;
});

model.attachedFunction = function() {
  assert(this.where, 'where should exist.');
}

// both should not throw
model.insert({});
(function changeScope() { model.attachedFunction(); })()

.include throws error on find query when result is empty

CREATE TABLE "user" (
  id SERIAL PRIMARY KEY,
  name text NOT NULL
);
CREATE TABLE "address" (
  id SERIAL PRIMARY KEY,
  user_id integer NOT NULL REFERENCES "user"(id),
  city text NOT NULL
);
userTable = database.table('user');
addressTable = database.table('address');

userTable
  .include({first: true}, addressTable)
  .find(function(users) {

  })
Unhandled rejection Error: `in` with empty array as right operand
  at Object.dsl.(anonymous function).modifiers.(anonymous function) [as in] (/app/node_modules/fragments-postgres/node_modules/mesa/node_modules/mohair/node_modules/criterion/src/criterion.js:423:17)
  at criterion (/app/node_modules/fragments-postgres/node_modules/mesa/node_modules/mohair/node_modules/criterion/src/criterion.js:603:21)
  at Object.Mohair.where (/app/node_modules/fragments-postgres/node_modules/mesa/node_modules/mohair/lib/mohair.js:565:23)
  at Object.Mesa.where (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:216:63)
  at /app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:605:30
From previous event:
  at reducer (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:601:20)
  at Array.reduce (native)
  at Object.Mesa.baseEmbed (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:635:21)
  at Object.Mesa.embed (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:642:17)
  at Object.bound (/app/node_modules/fragments-postgres/node_modules/mesa/node_modules/lodash/dist/lodash.js:957:21)
From previous event:
  at reducer (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:458:20)
  at Array.reduce (native)
  at Object.Mesa.runQueue (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:460:18)
  at Object.Mesa.afterQuery (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:475:17)
  at /app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:568:19
From previous event:
  at Object.Mesa.find (/app/node_modules/fragments-postgres/node_modules/mesa/lib/mesa.js:567:29)
  ....
  at processImmediate [as _immediateCallback] (timers.js:367:17)

where conditions are not escaped

As the attributes in insert and update are escaped via mohair.escape I expected the where conditions to be escaped, too.

model.where({someColumn: true}); // doesn't escape
model.where({'"someColumn"': true}); // manual escaping is tedious

As a hotfix I used this method

model.where(escape({someColumn: true}));
function escape(where) {
  if (Array.isArray(where)) {
    return where.map(escape);
  }
  return _.object(_.map(where, function(value, key) {
    var isSpecialKey = key[0] === '$';
    var quotedKey = isSpecialKey ? key : '"' + key + '"';
    return [quotedKey, isDictionary(value) ? escape(value) : value];
  }));

  function isDictionary(object) {
    return _.isObject(object) && !_.isFunction(object);
  }
}

Which currently works for normal keys, special keys ($or, ...), but not yet for raw sql (where('foo && ?', foo))

Would be handsome if this would be baked into mesa or configurable.

Do you have any opinions or preferences?

sync getConnection

is there a reason getConnection is async?
Or do you prefer the cleaner error management with async callbacks?

updated field

Just thought about this:

There is no easy method to have an updated field in postgres without using an orm or some kind of hack with a trigger.

so it would be great if one could define some logic like: "if the model has an update field default it to new Date"

it would be great if this logic wouldn't be part of core mesa, but could be easily added with generic logic.

what do you think, could this be part of mesa?

Minor usability glitch with chained promises

This is a minor usability glitch I discovered while working with the api.
I shot myself several times with this error. It occurred one time to often and therefore I will report it.

Instead of model.find().then(postProcess) I did model.find(postProcess) which will swallow the postProcess function and return something unexpected. As there will be no error it can get hard to detect the source of the problem

I would have 2 proposals to avoid this situation

a) assert to have no arguments for all functions without parameters (find, first, update, delete)
b) treat find(postProcess) as find().then(postProcess)

Do you think this is an glitch which should be fixed? And if yes do you have a preference on how to solve this?

escaping seems not to work

mesa = require 'mesa'
user = new mesa().table('user').connection(getConnection).attributes(['mail', 'password'])
user.insert {mail: 'foo', password: 'hashed'}, cb

returns this sql string

INSERT INTO user(mail, password) VALUES ($1, $2) RETURNING id

but should be

INSERT INTO "user" (mail, password) VALUES ($1, $2) RETURNING id

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.