Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Nogueira committed Jun 4, 2016
1 parent 1521901 commit 8a779bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: node_js

before_script:
- psql --version
- cp test/postgres/knexfile.js.dist test/postgres/knexfile.js
- cp test/sqlite/knexfile.js.dist test/sqlite/knexfile.js
- psql -U postgres -c 'create database "bookshelf-json-columns";'
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

function stringify() {
console.log('stringify');
this.jsonColumns.forEach(column => {
if (this.attributes[column]) {
this.attributes[column] = JSON.stringify(this.attributes[column]);
Expand All @@ -17,7 +16,6 @@ function stringify() {
*/

function parse() {
console.log('parse');
this.jsonColumns.forEach(column => {
if (this.attributes[column]) {
this.attributes[column] = JSON.parse(this.attributes[column]);
Expand All @@ -36,9 +34,12 @@ export default Bookshelf => {
Bookshelf.Model = Bookshelf.Model.extend({
initialize() {
if (!this.jsonColumns) {
console.log('foo');
return Model.initialize.apply(this, arguments);
}

console.log('bar');

// Stringify JSON columns before model is saved.
this.on('saving', stringify.bind(this));

Expand Down

0 comments on commit 8a779bb

Please sign in to comment.