Skip to content

Commit

Permalink
Add json support to the query builder for mysql (#2635)
Browse files Browse the repository at this point in the history
* Add json support to the query builder for mysql

refs #1036

Based on #1902

* Clarify supported version
  • Loading branch information
kibertoad authored and elhigu committed May 30, 2018
1 parent 5f8584c commit 4d4e4ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions .travis.yml
Expand Up @@ -31,9 +31,18 @@ after_script:
notifications:
email: false

services:
- mysql
addons:
postgresql: '9.6'
apt:
sources:
- mysql-5.7-trusty
packages:
- g++-4.8
- gcc-4.8
- g++-4.8
- gcc-4.8
- libmysqlclient-dev
- libmysqlclient20
- mysql-community-client
- mysql-common
- mysql-community-server
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@
# Master (Unreleased)

- Drop support for Node.js 4 and 5
- `json` data type is no longer converted to `text` within a schema builder migration for MySQL databases (note that JSON data type is only supported for MySQL 5.7.8+)

# 0.14.6 - 12 Apr, 2018

Expand Down
4 changes: 4 additions & 0 deletions src/dialects/mysql/schema/columncompiler.js
Expand Up @@ -95,6 +95,10 @@ assign(ColumnCompiler_MySQL.prototype, {
return length ? `varbinary(${this._num(length)})` : 'blob'
},

json() {
return 'json';
},

// Modifiers
// ------

Expand Down
9 changes: 9 additions & 0 deletions test/unit/schema/mysql.js
Expand Up @@ -54,6 +54,15 @@ describe(dialect + " SchemaBuilder", function() {
expect(tableSql[0].sql).to.equal('alter table `users` add `id` int unsigned not null auto_increment primary key, add `email` varchar(255)');
});

if(dialect !== 'maria') {
it('adding json', function() {
tableSql = client.schemaBuilder().table('user', function(t) {
t.json('preferences');
}).toSQL();
expect(tableSql[0].sql).to.equal('alter table `user` add `preferences` json');
});
}

it('test drop table', function() {
tableSql = client.schemaBuilder().dropTable('users').toSQL();

Expand Down

0 comments on commit 4d4e4ca

Please sign in to comment.