Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json type support for SQLite #2814

Merged
merged 2 commits into from Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dialects/sqlite3/schema/columncompiler.js
Expand Up @@ -22,4 +22,6 @@ ColumnCompiler_SQLite3.prototype.enu = function(allowed) {
)}'))`;
};

ColumnCompiler_SQLite3.prototype.json = 'json';

export default ColumnCompiler_SQLite3;
42 changes: 27 additions & 15 deletions test/unit/schema/sqlite3.js
Expand Up @@ -2,16 +2,15 @@

'use strict';

var tableSql;
let tableSql;

var sinon = require('sinon');
var SQLite3_Client = require('../../../lib/dialects/sqlite3');
var client = new SQLite3_Client({ client: 'sqlite3' });
var SQLite3_DDL = require('../../../lib/dialects/sqlite3/schema/ddl');
const sinon = require('sinon');
const SQLite3_Client = require('../../../lib/dialects/sqlite3');
const client = new SQLite3_Client({ client: 'sqlite3' });
const SQLite3_DDL = require('../../../lib/dialects/sqlite3/schema/ddl');

var _ = require('lodash');
var equal = require('assert').equal;
var deepEqual = require('assert').deepEqual;
const _ = require('lodash');
const { equal, deepEqual } = require('assert');

describe('SQLite SchemaBuilder', function() {
it('basic create table', function() {
Expand All @@ -30,6 +29,19 @@ describe('SQLite SchemaBuilder', function() {
);
});

it('create json table', function() {
tableSql = client
.schemaBuilder()
.createTable('user', function(table) {
table.json('preferences');
})
.table('user', function(t) {})
.toSQL();
expect(tableSql[0].sql).to.equal(
'create table `user` (`preferences` json)'
);
});

it('basic alter table', function() {
tableSql = client
.schemaBuilder()
Expand All @@ -40,7 +52,7 @@ describe('SQLite SchemaBuilder', function() {
.toSQL();

equal(2, tableSql.length);
var expected = [
const expected = [
'alter table `users` add column `id` integer not null primary key autoincrement',
'alter table `users` add column `email` varchar(255)',
];
Expand Down Expand Up @@ -605,7 +617,7 @@ describe('SQLite SchemaBuilder', function() {
.toSQL();

equal(2, tableSql.length);
var expected = [
const expected = [
'alter table `users` add column `created_at` datetime',
'alter table `users` add column `updated_at` datetime',
];
Expand Down Expand Up @@ -649,19 +661,19 @@ describe('SQLite SchemaBuilder', function() {
return client
.schemaBuilder()
.table('foo', function() {
var doReplace = SQLite3_DDL.prototype._doReplace;
const doReplace = SQLite3_DDL.prototype._doReplace;

var sql1 =
const sql1 =
'CREATE TABLE `foo` (`id` integer not null primary key autoincrement, ' +
'"parent_id_test" integer, foreign key("parent_id") references `foo`(`id`))';
var sql2 =
const sql2 =
'CREATE TABLE `foo` (`id` integer not null primary key autoincrement, ' +
'"parent_id_test" integer, foreign key("parent_id") references `bar`(`id`))';

var sql1b =
const sql1b =
'CREATE TABLE `foo` ("id_foo" integer not null primary key autoincrement, ' +
'"parent_id_test" integer, foreign key("parent_id") references `foo`("id_foo"))';
var sql2b =
const sql2b =
'CREATE TABLE `foo` ("id_foo" integer not null primary key autoincrement, ' +
'"parent_id_test" integer, foreign key("parent_id") references `bar`(`id`))';

Expand Down