From 6403d3f8d9dcf97c8135e4e82890bbb23c30df7d Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sat, 2 Sep 2017 21:27:32 -0600 Subject: [PATCH] Add json type (alias to TEXT) --- models/Grammars/Grammar.cfc | 4 ++++ models/Schema/Blueprint.cfc | 5 +++++ tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc | 8 ++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/models/Grammars/Grammar.cfc b/models/Grammars/Grammar.cfc index 5f8c6f6f..01cabfce 100644 --- a/models/Grammars/Grammar.cfc +++ b/models/Grammars/Grammar.cfc @@ -818,6 +818,10 @@ component displayname="Grammar" accessors="true" { return "INTEGER(#column.getPrecision()#)"; } + function typeJson( column ) { + return "TEXT"; + } + function typeString( column ) { return "VARCHAR(#column.getLength()#)"; } diff --git a/models/Schema/Blueprint.cfc b/models/Schema/Blueprint.cfc index 724001f7..5e29aa3d 100644 --- a/models/Schema/Blueprint.cfc +++ b/models/Schema/Blueprint.cfc @@ -118,6 +118,11 @@ component accessors="true" { return addColumn( argumentCollection = arguments ); } + function json( name ) { + arguments.type = "json"; + return addColumn( argumentCollection = arguments ); + } + function tinyInteger( name, length = "" ) { arguments.type = "tinyInteger"; return addColumn( argumentCollection = arguments ); diff --git a/tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc b/tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc index ea8e392f..d22bf2d8 100644 --- a/tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc +++ b/tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc @@ -210,8 +210,12 @@ component extends="testbox.system.BaseSpec" { expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""age"" INTEGER(2) NOT NULL)" ); } ); - xit( "json", function() { - fail( "test not implemented yet" ); + it( "json", function() { + var schema = getBuilder(); + var blueprint = schema.create( "users", function( table ) { + table.json( "personalizations" ); + }, false ); + expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""personalizations"" TEXT NOT NULL)" ); } ); xit( "longText", function() {