Skip to content

Commit

Permalink
Add bit type
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 22, 2017
1 parent c909f9f commit 48d0044
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions models/Grammars/Grammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,10 @@ component displayname="Grammar" accessors="true" {
return "BIGINT";
}

function typeBit( column ) {
return "BIT(#column.getLength()#)";
}

function typeBoolean( column ) {
return "TINYINT(1)";
}
Expand Down
5 changes: 5 additions & 0 deletions models/Schema/Blueprint.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ component accessors="true" {
return addColumn( argumentCollection = arguments );
}

function bit( name, length = 1 ) {
arguments.type = "bit";
return addColumn( argumentCollection = arguments );
}

function boolean( name ) {
arguments.length = 1;
arguments.type = "boolean";
Expand Down
16 changes: 16 additions & 0 deletions tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""weather_reports"" (""temperature"" BIGINT NOT NULL)" );
} );

it( "bit", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.bit( "active" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" BIT(1) NOT NULL)" );
} );

it( "bit (with length)", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.bit( "something", 4 );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""something"" BIT(4) NOT NULL)" );
} );

it( "boolean", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
Expand Down

0 comments on commit 48d0044

Please sign in to comment.