Description
Hello. I'm trying to figure out how to complete this function:
async executeQuery(
sql: ReturnType<typeof postgres>,
query: string,
args: { [key: string]: string | number | boolean }
): Promise<TBD> {
// TBD
}
query
contains named placeholders for parameters, and args
provides the values of those placeholders by key, which provides the placeholder name. I'm generically representing queries and dynamically providing their arguments.
I'm looking for the function's implementation and return type.
Is this possible to do in a safe way, with proper literal escaping?
(In case you're questioning the need to do this, it's for a series of benchmarking tests, each potentially written for a different platform, in a different framework, in a different language. Rather than copying the queries from implementation to implementation and maintaining them across implementations, I'm centralizing them. I don't even know what queries I'll end up using in the end, so I want to be able to centrally change the queries for all frameworks all at once as I experiment. The above is for the Deno implementation. Moreover, I won't be using the exact function above; it's just to teach me how to do this.)