diff --git a/lib/dialect/postgres.js b/lib/dialect/postgres.js index 62f7920e..9af13abc 100644 --- a/lib/dialect/postgres.js +++ b/lib/dialect/postgres.js @@ -118,6 +118,7 @@ Postgres.prototype.visit = function(node) { case 'HAVING' : return this.visitHaving(node); case 'RETURNING' : return this.visitReturning(node); case 'ONDUPLICATE' : return this.visitOnDuplicate(node); + case 'COMMENT' : return this.visitComment(node); case 'FOR UPDATE' : return this.visitForUpdate(); case 'FOR SHARE' : return this.visitForShare(); case 'TABLE' : return this.visitTable(node); @@ -756,6 +757,10 @@ Postgres.prototype.visitRename = function(rename) { return ['RENAME TO ' + this.visit(rename.nodes[0])]; }; +Postgres.prototype.visitComment = function(node) { + return '/**' + node.comment + '**/'; +} + Postgres.prototype.visitIfExists = function() { return ['IF EXISTS']; }; diff --git a/lib/node/comment.js b/lib/node/comment.js new file mode 100644 index 00000000..b9e46712 --- /dev/null +++ b/lib/node/comment.js @@ -0,0 +1,12 @@ +'use strict'; + +var Node = require(__dirname); + +module.exports = Node.define({ + type: 'COMMENT', + constructor: function(table, comment) { + Node.call(this); + + this.comment = comment; + }, +}); diff --git a/lib/node/query.js b/lib/node/query.js index ff5fe24a..00378ea7 100644 --- a/lib/node/query.js +++ b/lib/node/query.js @@ -16,6 +16,7 @@ var Update = require('./update'); var Delete = require('./delete'); var Returning = require('./returning'); var OnDuplicate = require('./onDuplicate'); +var Comment = require('./comment'); var ForUpdate = require('./forUpdate'); var ForShare = require('./forShare'); var Create = require('./create'); @@ -274,6 +275,10 @@ var Query = Node.define({ return self.add(onDuplicate); }, + addComment: function(comment) { + return this.add(new Comment(this.table, comment)); + }, + forUpdate: function() { assert(typeof this._select !== 'undefined', 'FOR UPDATE can be used only in a select statement'); this.add(new ForUpdate()); diff --git a/test/dialects/insert-tests.js b/test/dialects/insert-tests.js index aaab33d5..f34a02c8 100644 --- a/test/dialects/insert-tests.js +++ b/test/dialects/insert-tests.js @@ -434,3 +434,15 @@ Harness.test({ }, params: ['test', 2, 'testupdate'] }); + +Harness.test({ + query: post.insert({ + content: 'test', + userId: 2 + }).addComment('db=hostgroup').addComment('shard=1'), + mysql: { + text : 'INSERT INTO `post` (`content`, `userId`) VALUES (?, ?) /**db=hostgroup**/ /**shard=1**/', + string: 'INSERT INTO `post` (`content`, `userId`) VALUES (\'test\', 2) /**db=hostgroup**/ /**shard=1**/' + }, + params: ['test', 2] +});