Forked from guitrspaz/cfdao.returnRecordFound.sublime-snippet
Last active
July 26, 2017 14:23
-
-
Save obxpete/9e3626bf4e80575c2415247824c5d85e to your computer and use it in GitHub Desktop.
Query function to return a boolean value. Example use case: find if item exists.
This file contains hidden or 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
<snippet> | |
<content><![CDATA[/** | |
* @name: ${TM_FILENAME/(.+)\..+|.*/$1/:name}.${1:functionName} | |
* @hint: ${2:Description} | |
* @returns: Boolean for whether a record exists | |
* @date: ${3:Date} | |
* @author: $TM_FULLNAME ($TM_EMAIL) | |
*/ | |
${4:public} Boolean function ${1:functionName}( | |
${5} | |
){ | |
var errorStruct={ | |
arguments:arguments, | |
logType:"warning", | |
start:Now(), | |
stackTrace:getStackTrace(), | |
sql:{ | |
string:"", | |
prefix:{} | |
}, | |
result:0 | |
}; | |
try{ | |
transaction action="begin" isolation="read_uncommitted" { | |
var queryService=new Query( | |
name="q${1}", | |
datasource=this.getdsn() | |
); | |
savecontent variable="errorStruct.sql.string"{ | |
WriteOutput(' | |
${6} | |
'); | |
} | |
var queryData=queryService.execute(sql=errorStruct.sql.string); | |
errorStruct.sql.prefix=queryData.getPrefix(); | |
} | |
transaction action="commit"; | |
if( structKeyExists(errorStruct.sql.prefix,'RECORDCOUNT') | |
&& isValid('numeric',errorStruct.sql.prefix.RECORDCOUNT) | |
&& errorStruct.sql.prefix.RECORDCOUNT | |
){ | |
errorStruct.result=1; | |
} | |
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 errorStruct.result; | |
} | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>daoboolean</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