Skip to content

Commit

Permalink
Add date, datetime, time, and timestamp types.
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 22, 2017
1 parent 5732161 commit 857bdcf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
12 changes: 12 additions & 0 deletions models/Grammars/Grammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,14 @@ component displayname="Grammar" accessors="true" {
return "CHAR(#column.getLength()#)";
}

function typeDate( column ) {
return "DATE";
}

function typeDatetime( column ) {
return "DATETIME";
}

function typeInteger( column ) {
return "INTEGER(#column.getPrecision()#)";
}
Expand All @@ -795,6 +803,10 @@ component displayname="Grammar" accessors="true" {
return "TEXT";
}

function typeTime( column ) {
return "TIME";
}

function typeTimestamp( column ) {
return "TIMESTAMP";
}
Expand Down
15 changes: 15 additions & 0 deletions models/Schema/Blueprint.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ component accessors="true" {
return addColumn( argumentCollection = arguments );
}

function date( name ) {
arguments.type = "date";
return addColumn( argumentCollection = arguments );
}

function datetime( name ) {
arguments.type = "datetime";
return addColumn( argumentCollection = arguments );
}

function increments( name ) {
arguments.autoIncrement = true;
addIndex( type = "primary", column = name );
Expand Down Expand Up @@ -121,6 +131,11 @@ component accessors="true" {
return addColumn( argumentCollection = arguments );
}

function time( name ) {
arguments.type = "time";
return addColumn( argumentCollection = arguments );
}

function timestamp( name ) {
arguments.type = "timestamp";
return addColumn( argumentCollection = arguments );
Expand Down
44 changes: 24 additions & 20 deletions tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,20 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""classifications"" (""abbreviation"" CHAR(255) NOT NULL)" );
} );

xit( "date", function() {
fail( "test not implemented yet" );
} );

xit( "dateTime", function() {
fail( "test not implemented yet" );
it( "date", function() {
var schema = getBuilder();
var blueprint = schema.create( "posts", function( table ) {
table.date( "posted_date" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""posts"" (""posted_date"" DATE NOT NULL)" );
} );

xit( "dateTimeTz", function() {
fail( "test not implemented yet" );
it( "datetime", function() {
var schema = getBuilder();
var blueprint = schema.create( "posts", function( table ) {
table.datetime( "posted_date" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""posts"" (""posted_date"" DATETIME NOT NULL)" );
} );

xit( "decimal", function() {
Expand Down Expand Up @@ -194,12 +198,12 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""posts"" (""body"" TEXT NOT NULL)" );
} );

xit( "time", function() {
fail( "test not implemented yet" );
} );

xit( "timeTz", function() {
fail( "test not implemented yet" );
it( "time", function() {
var schema = getBuilder();
var blueprint = schema.create( "recurring_tasks", function( table ) {
table.time( "fire_time" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""recurring_tasks"" (""fire_time"" TIME NOT NULL)" );
} );

it( "tinyInteger", function() {
Expand All @@ -218,12 +222,12 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" TINYINT(3) NOT NULL)" );
} );

xit( "timestamp", function() {
fail( "test not implemented yet" );
} );

xit( "timestampTz", function() {
fail( "test not implemented yet" );
it( "timestamp", function() {
var schema = getBuilder();
var blueprint = schema.create( "posts", function( table ) {
table.timestamp( "posted_date" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""posts"" (""posted_date"" TIMESTAMP NOT NULL)" );
} );

it( "unsignedBigInteger", function() {
Expand Down

0 comments on commit 857bdcf

Please sign in to comment.