Created
April 13, 2023 02:46
-
-
Save Zomatree/0553fe5f18720c72bfbcd46b0cb603c1 to your computer and use it in GitHub Desktop.
Type-safe sql parameters
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
type IsValid<Name> = Name extends `${infer _} ${infer _}` | |
? never | |
: Name; | |
type IsParameter<Part> = Part extends `\$${infer Parameter}` | |
? IsValid<Parameter> | |
: never; | |
type QueryParser<Query> = Query extends `${infer A}${' ' | '='}${infer B}` | |
? IsParameter<A> | QueryParser<B> | |
: IsParameter<Query>; | |
type QueryParameters<Query> = { | |
[Key in QueryParser<Query>]: string | |
}; | |
function execute<const Query>(query: Query, parameters: QueryParameters<Query>): any {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment