Skip to content

Commit

Permalink
fix(QueryBuilder): Allow for setting any Grammar, including AutoDiscover
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Jan 21, 2025
1 parent a3db3c6 commit 88b54a2
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 507 deletions.
329 changes: 111 additions & 218 deletions models/Grammars/BaseGrammar.cfc

Large diffs are not rendered by default.

20 changes: 6 additions & 14 deletions models/Grammars/MySQLGrammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,12 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
setShouldWrapValues( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() );
}

return arrayToList(
arrayFilter(
[
"RENAME TABLE",
wrapTable( blueprint.getTable() ),
"TO",
wrapTable( commandParameters.to )
],
function( item ) {
return item != "";
}
),
" "
);
return concatenate( [
"RENAME TABLE",
wrapTable( blueprint.getTable() ),
"TO",
wrapTable( commandParameters.to )
] );
} finally {
if ( !isNull( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() ) ) {
setShouldWrapValues( originalShouldWrapValues );
Expand Down
106 changes: 32 additions & 74 deletions models/Grammars/OracleGrammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,7 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
generateComment( column, blueprint )
];

return arrayToList(
arrayFilter( values, function( item ) {
return item != "";
} ),
" "
);
return concatenate( values );
} finally {
if ( !isNull( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() ) ) {
setShouldWrapValues( originalShouldWrapValues );
Expand All @@ -389,22 +384,14 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
setShouldWrapValues( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() );
}

return arrayToList(
arrayFilter(
[
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"RENAME COLUMN",
wrapColumn( commandParameters.from ),
"TO",
wrapColumn( commandParameters.to.getName() )
],
function( item ) {
return item != "";
}
),
" "
);
return concatenate( [
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"RENAME COLUMN",
wrapColumn( commandParameters.from ),
"TO",
wrapColumn( commandParameters.to.getName() )
] );
} finally {
if ( !isNull( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() ) ) {
setShouldWrapValues( originalShouldWrapValues );
Expand All @@ -422,33 +409,20 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
var originalIndexes = blueprint.getIndexes();
blueprint.setIndexes( [] );

var body = arrayToList(
arrayFilter( [ compileCreateColumn( commandParameters.column, blueprint ) ], function( item ) {
return item != "";
} ),
", "
);
var body = concatenate( [ compileCreateColumn( commandParameters.column, blueprint ) ], ", " );

for ( var index in blueprint.getIndexes() ) {
blueprint.addConstraint( index );
}

blueprint.setIndexes( originalIndexes );

return arrayToList(
arrayFilter(
[
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"ADD",
body
],
function( item ) {
return item != "";
}
),
" "
);
return concatenate( [
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"ADD",
body
] );
} finally {
if ( !isNull( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() ) ) {
setShouldWrapValues( originalShouldWrapValues );
Expand All @@ -463,20 +437,12 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
setShouldWrapValues( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() );
}

return arrayToList(
arrayFilter(
[
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"MODIFY",
"(" & compileCreateColumn( commandParameters.to, blueprint ) & ")"
],
function( item ) {
return item != "";
}
),
" "
);
return concatenate( [
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"MODIFY",
"(" & compileCreateColumn( commandParameters.to, blueprint ) & ")"
] );
} finally {
if ( !isNull( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() ) ) {
setShouldWrapValues( originalShouldWrapValues );
Expand All @@ -491,22 +457,14 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
setShouldWrapValues( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() );
}

return arrayToList(
arrayFilter(
[
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"RENAME CONSTRAINT",
wrapColumn( commandParameters.from ),
"TO",
wrapColumn( commandParameters.to )
],
function( item ) {
return item != "";
}
),
" "
);
return concatenate( [
"ALTER TABLE",
wrapTable( blueprint.getTable() ),
"RENAME CONSTRAINT",
wrapColumn( commandParameters.from ),
"TO",
wrapColumn( commandParameters.to )
] );
} finally {
if ( !isNull( arguments.blueprint.getSchemaBuilder().getShouldWrapValues() ) ) {
setShouldWrapValues( originalShouldWrapValues );
Expand Down Expand Up @@ -779,9 +737,9 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
return sql;
}

function compileColumnExists( table, column, scehma = "" ) {
function compileColumnExists( table, column, schema = "" ) {
var sql = "SELECT 1 FROM #wrapTable( "all_tab_columns" )# WHERE #wrapColumn( "table_name" )# = ? AND #wrapColumn( "column_name" )# = ?";
if ( scehma != "" ) {
if ( schema != "" ) {
sql &= " AND #wrapColumn( "owner" )# = ?";
}
return sql;
Expand Down
Loading

0 comments on commit 88b54a2

Please sign in to comment.