-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SqlCommenter): Pass bindings to commenters.
Also includes a sample `BindingsCommenter`.
- Loading branch information
Showing
9 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
component singleton accessors="true" { | ||
|
||
property name="properties"; | ||
|
||
/** | ||
* Returns a struct of key/value comment pairs to append to the SQL. | ||
* | ||
* @sql The SQL to append the comments to. This is provided if you need to | ||
* inspect the SQL to make any decisions about what comments to return. | ||
* @datasource The datasource that will execute the query. If null, the default datasource will be used. | ||
* This can be used to make decisions about what comments to return. | ||
*/ | ||
public struct function getComments( required string sql, string datasource, array bindings = [] ) { | ||
return { "bindings": serializeBindings( bindings = bindings, delimiter = ";" ) }; | ||
} | ||
|
||
private string function serializeBindings( required array bindings, string delimiter = ";" ) { | ||
return bindings | ||
.map( function( binding ) { | ||
return limitString( | ||
str = castAsSqlType( | ||
value = binding.null ? javacast( "null", "" ) : binding.value, | ||
sqltype = binding.cfsqltype | ||
), | ||
limit = 100 | ||
); | ||
} ) | ||
.toList( delimiter ); | ||
} | ||
|
||
private string function limitString( required string str, required numeric limit, string end = "..." ) { | ||
if ( len( arguments.str ) <= arguments.limit ) { | ||
return arguments.str; | ||
} | ||
|
||
return left( arguments.str, arguments.limit ) & arguments.end; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters