Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Related to https://github.com/dresende/node-orm/issues/36#37

Closed
shine-on wants to merge 15 commits into
dresende:masterfrom
shine-on:master
Closed

Related to https://github.com/dresende/node-orm/issues/36#37
shine-on wants to merge 15 commits into
dresende:masterfrom
shine-on:master

Conversation

@shine-on
Copy link
Copy Markdown

Allows to

CREATE TABLE "product" ("id" SERIAL, "name" VARCHAR(255) NOT NULL, "description" VARCHAR(255) DEFAULT '', "datecreated" TIMESTAMP NOT NULL, PRIMARY KEY ("id"))

INSERT INTO "product" ("name", "datecreated") VALUES ($1, $2) [ 'Birds', '2012-02-12T18:10:46.133Z' ]

without error about constraint violation. Attributes without DEFAULT must be NOT NULL and populated by user.

On UPDATE, allow to accept partial model updates.

Assume the following scenario:

  • client creates a model;
  • server saves a model, but also sets some special attributes ("datecreated", for example);
  • server responses with partial model with "datecreated" sliced out during afterSave hook;
  • client accepts partial model which can be edited and saved back again without knowing of special attributes.

Another scenario may looks like:

  • client A creates a model;
  • server saves a model;
  • client B retrieves a model;
  • server slices out "balance" attribute because server Access Control List allows "balance" only for Creator role, which is client A, and not client B;
  • client B accepts partial model which can be edited and saved back.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand these changes, but not the ones on orm.js.

@dresende
Copy link
Copy Markdown
Owner

OK, I think I understand now, the diff is not very smart and mixed a lot of same lines just because of different indentation. If the next lines make sense to you and you agree, I'll change the behavior:

  • Default values defined in model are passed to the database connectors to the CREATE TABLE
  • Default values are not added to a record when some properties are missing
  • If one wants to change this behavior, he/she can use the beforeSave hook

@shine-on
Copy link
Copy Markdown
Author

Well, above three is exactly what my diffs do :)

  • introduce constraints (which btw was documented but not implemented);
  • avoid undefined properties in data;
  • allow to set default values from application code, rather than setting them internally.

Regarding, connectors' code duplication, I'm planning to wrote a prototype class (says, Connector) implementing DBQuery, DBClient and such so individual connectors can extend without repetitive code.

@dresende
Copy link
Copy Markdown
Owner

Ok, I'll make the changes on my local repo (I can't merge automatically now) and I'll assign you as the author. In lib/databases/ you have an example.js DBClient which should be updated.

For SQL databases some methods could be reused but for example for MongoDB this is not so easy (and contraints don't apply). In the case of MongoDB (or CouchDB) the database connectors need to have access to the contraints to apply them.

@dresende dresende closed this in 914cfab Feb 26, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants