summaryrefslogtreecommitdiff
path: root/lib/db
diff options
context:
space:
mode:
Diffstat (limited to 'lib/db')
-rw-r--r--lib/db/bookshelf.js9
-rw-r--r--lib/db/index.js17
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/db/bookshelf.js b/lib/db/bookshelf.js
index 5774120..69157cc 100644
--- a/lib/db/bookshelf.js
+++ b/lib/db/bookshelf.js
@@ -5,7 +5,14 @@ var knex = require('knex')({
user : process.env.DB_USER,
password : process.env.DB_PASS,
database : process.env.DB_NAME,
- charset : 'utf8'
+ charset : 'utf8',
+ typecast : function (field, next) {
+ console.log(field.type)
+ if (field.type == 'BLOB') {
+ return field.string()
+ }
+ return next()
+ }
}
})
diff --git a/lib/db/index.js b/lib/db/index.js
index 2c8486b..994187e 100644
--- a/lib/db/index.js
+++ b/lib/db/index.js
@@ -83,8 +83,23 @@ db.getCommentsForThread = function (id, limit, offset){
if (offset) {
qb = qb.offset(offset)
}
- }).fetchAll()
+ }).fetchAll().then(function(comments){
+ comments.forEach(function(comment){
+ comment.set("comment", comment.get("comment").toString() )
+ })
+ return comments
+ })
}
db.getCommentCounts = function(ids){
return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread')
}
+
+/* PRIVATE MESSAGES */
+
+db.getMessage = function (id){
+ var model = new Message({'id': id})
+ return model.fetch().then(function(message){
+ message.set("body", message.get("body").toString() )
+ return message
+ })
+} \ No newline at end of file