You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see there was some discussion of supporting named parameters in grncdr/node-any-db-adapter-spec#7, but it isn't entirely clear to me from the actual package readmes how to go about using them in the usual any-db paradigm of "write SQL here, get parameters from there, pass both to query" unless I'm supposed to build the SQL using the parameters every time with the any-db-parameters helper.
Ideally, what I'd like is to be able to write code like this:
functionqueryWithNamedParameters(connection,sql,parameters,callback,prefix){// parameters is an object/hashmapif(!connection.supportsNamedParameters){// HYPOTHETICAL: this is what I am looking forletparser=/([\s\S]*?)('(?:''|[^'])*'|"(?:""|[^"])*"|[[](?:]]|[^\]])*]|\/[*][\s\S]*?[*]\/|--.*?(?:\n|$)|$)/g// breaks SQL up into comments/strings and non-comment/string segments so we can replace variables only outside comments/stringsletsqlTransformed=""letparametersTransformed=[]for(letmatch=parser.exec(sql);match[0]!="";match=parser.exec(sql)){constparameter=newRegExp(escapeRegExp(prefix||"$")+"([a-zA-Z]+)")while(parameter.test(match[1])){parametersTransformed.push(parameters[parameter.exec(match[1])[1]])match[1]=match[1].replace(parameter,"?")}sqlTransformed+=match[1]+match[2]}sql=sqlTransformedparameters=parametersTransformed}returnconnection.query(sql,parameters,callback)}
...Which, in case it isn't clear, would basically turn named parameters into positional ones (assuming I've written it right), but only if the specific database doesn't already support positional parameters (in which case they would be used against the database directly).
The text was updated successfully, but these errors were encountered:
Thanks, I will keep that handy; but I'm really more concerned with whether there's a way to detect whether an any-db-compliant database adaptor already supports named parameters so I only have to use a converter for databases that don't.
I see there was some discussion of supporting named parameters in grncdr/node-any-db-adapter-spec#7, but it isn't entirely clear to me from the actual package readmes how to go about using them in the usual any-db paradigm of "write SQL here, get parameters from there, pass both to
query
" unless I'm supposed to build the SQL using the parameters every time with the any-db-parameters helper.Ideally, what I'd like is to be able to write code like this:
...Which, in case it isn't clear, would basically turn named parameters into positional ones (assuming I've written it right), but only if the specific database doesn't already support positional parameters (in which case they would be used against the database directly).
The text was updated successfully, but these errors were encountered: