Skip to content

Commit

Permalink
feat(SchemaBuilder): Add support for MONEY and SMALLMONEY data types
Browse files Browse the repository at this point in the history
  • Loading branch information
MordantWastrel committed May 17, 2020
1 parent 3479c21 commit 24aadec
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 0 deletions.
8 changes: 8 additions & 0 deletions models/Grammars/BaseGrammar.cfc
Expand Up @@ -1251,6 +1251,14 @@ component displayname="Grammar" accessors="true" singleton {
return "TEXT";
}

function typeMoney( column ) {
return typeInteger( column );
}

function typeSmallMoney( column ) {
return typeInteger( column );
}

function typeUnicodeLongText( column ) {
return "TEXT";
}
Expand Down
8 changes: 8 additions & 0 deletions models/Grammars/OracleGrammar.cfc
Expand Up @@ -391,6 +391,14 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
return "CLOB";
}

function typeMoney( column ) {
return "NUMBER(19, 4)";
}

function typeSmallMoney( column ) {
return "NUMBER(10, 4)";
}

function typePoint( column ) {
return "SDO_GEOMETRY";
}
Expand Down
8 changes: 8 additions & 0 deletions models/Grammars/PostgresGrammar.cfc
Expand Up @@ -284,6 +284,14 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
return "INTEGER";
}

function typeMoney( column ) {
return "MONEY";
}

function typeSmallMoney( column ) {
return typeMoney( column );
}

function typePoint( column ) {
return formatPostGisType( "point" );
}
Expand Down
8 changes: 8 additions & 0 deletions models/Grammars/SqlServerGrammar.cfc
Expand Up @@ -423,6 +423,14 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
return "VARCHAR(MAX)";
}

function typeMoney( column ) {
return "MONEY";
}

function typeSmallMoney( column ) {
return "SMALLMONEY";
}

function typeUnicodeMediumText( column ) {
return "NVARCHAR(MAX)";
}
Expand Down
10 changes: 10 additions & 0 deletions models/Schema/Blueprint.cfc
Expand Up @@ -143,6 +143,16 @@ component accessors="true" {
return appendColumn( argumentCollection = arguments );
}

function money( name ) {
arguments.type = "money";
return appendColumn( argumentCollection = arguments );
}

function smallMoney( name ) {
arguments.type = "smallMoney";
return appendColumn( argumentCollection = arguments );
}

function morphs( name ) {
unsignedInteger( "#name#_id" );
string( "#name#_type" );
Expand Down
26 changes: 26 additions & 0 deletions tests/resources/AbstractSchemaBuilderSpec.cfc
Expand Up @@ -456,6 +456,32 @@ component extends="testbox.system.BaseSpec" {
}, mediumText() );
} );

it( "money", function() {
testCase( function( schema ) {
return schema.create(
"transactions",
function( table ) {
table.money( "amount" );
},
{},
false
);
}, money() );
} );

it( "smallMoney", function() {
testCase( function( schema ) {
return schema.create(
"transactions",
function( table ) {
table.smallMoney( "amount" );
},
{},
false
);
}, smallMoney() );
} );

it( "morphs", function() {
testCase( function( schema ) {
return schema.create(
Expand Down
8 changes: 8 additions & 0 deletions tests/specs/Schema/MySQLSchemaBuilderSpec.cfc
Expand Up @@ -144,6 +144,14 @@ component extends="tests.resources.AbstractSchemaBuilderSpec" {
return [ "CREATE TABLE `posts` (`body` TEXT NOT NULL)" ];
}

function money() {
return [ "CREATE TABLE `transactions` (`amount` INTEGER NOT NULL)" ];
}

function smallMoney() {
return [ "CREATE TABLE `transactions` (`amount` INTEGER NOT NULL)" ];
}

function morphs() {
return [
"CREATE TABLE `tags` (`taggable_id` INTEGER UNSIGNED NOT NULL, `taggable_type` VARCHAR(255) NOT NULL, INDEX `taggable_index` (`taggable_id`, `taggable_type`))"
Expand Down
8 changes: 8 additions & 0 deletions tests/specs/Schema/OracleSchemaBuilderSpec.cfc
Expand Up @@ -154,6 +154,14 @@ component extends="tests.resources.AbstractSchemaBuilderSpec" {
return [ "CREATE TABLE ""POSTS"" (""BODY"" CLOB NOT NULL)" ];
}

function money() {
return [ "CREATE TABLE ""TRANSACTIONS"" (""AMOUNT"" NUMBER(19, 4) NOT NULL)" ];
}

function smallMoney() {
return [ "CREATE TABLE ""TRANSACTIONS"" (""AMOUNT"" NUMBER(10, 4) NOT NULL)" ];
}

function morphs() {
return [
"CREATE TABLE ""TAGS"" (""TAGGABLE_ID"" NUMBER(10, 0) NOT NULL, ""TAGGABLE_TYPE"" VARCHAR2(255) NOT NULL)",
Expand Down
8 changes: 8 additions & 0 deletions tests/specs/Schema/PostgresSchemaBuilderSpec.cfc
Expand Up @@ -141,6 +141,14 @@ component extends="tests.resources.AbstractSchemaBuilderSpec" {
return [ "CREATE TABLE ""posts"" (""body"" TEXT NOT NULL)" ];
}

function money() {
return [ "CREATE TABLE ""transactions"" (""amount"" MONEY NOT NULL)" ];
}

function smallMoney() {
return [ "CREATE TABLE ""transactions"" (""amount"" MONEY NOT NULL)" ];
}

function morphs() {
return [
"CREATE TABLE ""tags"" (""taggable_id"" INTEGER NOT NULL, ""taggable_type"" VARCHAR(255) NOT NULL)",
Expand Down
8 changes: 8 additions & 0 deletions tests/specs/Schema/SqlServerSchemaBuilderSpec.cfc
Expand Up @@ -144,6 +144,14 @@ component extends="tests.resources.AbstractSchemaBuilderSpec" {
return [ "CREATE TABLE [posts] ([body] NVARCHAR(MAX) NOT NULL)" ];
}

function money() {
return [ "CREATE TABLE [transactions] ([amount] MONEY NOT NULL)" ];
}

function smallMoney() {
return [ "CREATE TABLE [transactions] ([amount] SMALLMONEY NOT NULL)" ];
}

function morphs() {
return [
"CREATE TABLE [tags] ([taggable_id] INTEGER NOT NULL, [taggable_type] VARCHAR(255) NOT NULL, INDEX [taggable_index] ([taggable_id], [taggable_type]))"
Expand Down

0 comments on commit 24aadec

Please sign in to comment.