Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save obxpete/d5785bd20fef6f9d9fd8709707aca7d9 to your computer and use it in GitHub Desktop.
Save obxpete/d5785bd20fef6f9d9fd8709707aca7d9 to your computer and use it in GitHub Desktop.
Creates a query function that returns the query result
<snippet>
<content><![CDATA[/**
* @name: ${TM_FILENAME/(.+)\..+|.*/$1/:name}.${1:functionName}
* @hint: ${2:Description}
* @returns: Query
* @date: ${3:Date}
* @author: $TM_FULLNAME ($TM_EMAIL)
*/
${4:public} Query function ${1:functionName}(
${7}
){
var errorStruct={
arguments:arguments,
logType:"warning",
start:Now(),
stackTrace:getStackTrace(),
sql:{
string:"",
prefix:{}
}
};
var result=QueryNew('id','varchar');
try{
transaction action="begin" isolation="read_uncommitted" {
var queryService=new Query(
name="q${1}",
datasource=this.getdsn()
);
savecontent variable="errorStruct.sql.string"{
WriteOutput('
${8}
');
}
var queryData=queryService.execute(sql=errorStruct.sql.string);
errorStruct.sql.prefix=queryData.getPrefix();
result=queryData.getResult();
}
transaction action="commit";
errorStruct.logType="information";
} catch( Any e ){
transaction action="rollback";
errorStruct.logType="error";
errorStruct.cfcatch=e;
}
errorStruct.end=Now();
errorStruct.diff=DateDiff('s',errorStruct.start,errorStruct.end);
if( errorStruct.logType!='information' || this.getdebugMode() ){
createLog(
logName=this.getdefaultLog(),
logType=errorStruct.logType,
functName=this.getcaller()&".${1:functionName}()",
args=errorStruct
);
}
return result;
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dao.query</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment