Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

document the two option flags

  • Loading branch information...
commit 4577546a92abb3b133302d10871424486aff5377 1 parent 09dfcc7
@mgutz authored
Showing with 12 additions and 9 deletions.
  1. +12 −9 README.md
View
21 README.md
@@ -30,8 +30,11 @@ The current implementeation is used in `test/integration/integrationTest.js`.
Conect to Database
var Mapper = require('mapper');
- var conn = { user: 'dont', password: 'blink', database: 'now' };
- Mapper.connect(conn);
+ var conn = { user: 'grace', password: 'secret', database: 'app_dev' };
+
+ // set verbose flag to trace SQL
+ // set strict to be warned of invalid columns in JSON objects
+ Mapper.connect(conn, {verbose: true, strict: false});
Define Data Access Objects
@@ -48,26 +51,26 @@ CRUD
var insertId;
+ // insert a new post
Post.insert({ title: 'First Post' }).exec(function(err, result) {
insertId = result.insertId;
});
+ // select inserted post
Post.where({ id: insertId }).one(function(err, post) {
assert.equal(post.title, 'First Post,');
});
- Post.set({ title: 'New Title' }).exec(function(err, result) {
- assert.equal(result.affectedRows, 1);
- });
-
+ // update inserted post
Post
- .update()
- .where({ id: insertId })
+ .update() // optional since set() is used
.set({ title: 'New Title' })
+ .where({ id: insertId })
.exec(function (err, result) {
- // ...
+ assert.equal(result.affectedRows, 1);
});
+ // delete all posts with a specific title
Post.delete().where({ title: 'New Title' }).exec(function(err, result) {
assert.equal(result.affectedRows, 1);
});
Please sign in to comment.
Something went wrong with that request. Please try again.