Skip to content

Commit

Permalink
Add enum type.
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 22, 2017
1 parent aa13c72 commit e2f17ab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions models/Grammars/Grammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,13 @@ component displayname="Grammar" accessors="true" {
return "DECIMAL(#column.getLength()#,#column.getPrecision()#)";
}

function typeEnum( column ) {
var values = column.getValues().map( function ( value ) {
return wrapValue( value );
} ).toList( "," );
return "ENUM(#values#)";
}

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

function enum( name, values ) {
arguments.type = "enum";
return addColumn( argumentCollection = arguments );
}

function increments( name ) {
arguments.autoIncrement = true;
addIndex( type = "primary", column = name );
Expand Down
2 changes: 2 additions & 0 deletions models/Schema/Column.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ component accessors="true" {
property name="unsigned" default="false";
property name="autoIncrement" default="false";
property name="default" default="";
property name="values";

function init( blueprint ) {
setBlueprint( blueprint );
variables.values = [];
return this;
}

Expand Down
8 changes: 6 additions & 2 deletions tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""employees"" (""salary"" DECIMAL(3,2) NOT NULL)" );
} );

xit( "enum", function() {
fail( "test not implemented yet" );
it( "enum", function() {
var schema = getBuilder();
var blueprint = schema.create( "employees", function( table ) {
table.enum( "tshirt_size", [ "S", "M", "L", "XL", "XXL" ] );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""employees"" (""tshirt_size"" ENUM(""S"",""M"",""L"",""XL"",""XXL"") NOT NULL)" );
} );

xit( "float", function() {
Expand Down

0 comments on commit e2f17ab

Please sign in to comment.