Permalink
Browse files

fix(examples): fixed `setup` and `done` actions

  • Loading branch information...
Rawphs
Rawphs committed Mar 24, 2017
1 parent c595dd2 commit 5e66163e1b7f8aad4fe3154b3dfe18896ba084fe
Showing with 25 additions and 21 deletions.
  1. +15 −21 examples/todo/todo.js
  2. +10 −0 examples/todo/wetland.js
@@ -1,29 +1,20 @@
"use strict";
'use strict';
const util = require('util');
const Wetland = require('wetland').Wetland;
const List = require('./entity/List');
const Todo = require('./entity/Todo');
const wetland = new Wetland({
entityPath: __dirname + '/entity',
stores : {
defaultStore: {
client : 'sqlite3',
useNullAsDefault: true,
connection : {filename: `./todo.sqlite`}
}
}
});
const wetland = new Wetland(require('./wetland.js'));
function todo(parameters) {
function todo (parameters) {
let action = parameters[2];
let list = parameters[3];
let todo = parameters[4];
let manager = wetland.getManager();
if (action === 'setup') {
return wetland.getMigrator().create().apply()
return wetland.getMigrator().devMigrations()
.then(() => console.log('Tables created.'));
}
@@ -55,7 +46,7 @@ function todo(parameters) {
if (action === 'show-all') {
return manager.getRepository(List).find(null, {join: ['todos']})
.then(all => console.log(util.inspect(all, { depth: 8 })));
.then(all => console.log(util.inspect(all, {depth: 8})));
}
if (action === 'add-todo') {
@@ -72,13 +63,16 @@ function todo(parameters) {
}
if (action === 'done') {
return manager.getRepository(Todo).getQueryBuilder('t')
.update({done: true})
.innerJoin('t.list', 'l')
.where({'t.task': todo, 'l.name': list})
.getQuery()
.execute()
.then(() => console.log(`Todo '${todo}' done is done.`));
return manager.getRepository(Todo)
.find({'t.task': todo}, {alias: 't', populate: 't.list'})
.then(all => {
let rowToUpdate = all.filter(row => row.list.name === list)[0];
rowToUpdate.done = true;
return manager.flush();
})
.then(() => console.log(`Todo '${todo}' from list '${list}' was set as done.`));
}
if (action === 'remove-todo') {
@@ -0,0 +1,10 @@
module.exports = {
entityPath: __dirname + '/entity',
stores : {
defaultStore: {
client : 'sqlite3',
useNullAsDefault: true,
connection : {filename: `./todo.sqlite`}
}
}
};

0 comments on commit 5e66163

Please sign in to comment.