Last active
June 14, 2021 20:14
-
-
Save max10rogerio/f2ead85854d24e0cf1106006c0d2a6e3 to your computer and use it in GitHub Desktop.
Revisions
-
max10rogerio revised this gist
Mar 9, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // Example // https://www.typescriptlang.org/play?#code/MYewdgziA2CmB0w4EMBOAKAlAKG6SALgATCqzIGwBKsAZrGWMLEQLxHpm0BcRYArgFsARg0y8IBVAEswAczYA+IgAMAOgBINAby4BfFXnCSSZCrAAKaZINiVUAaVgBPNhwDWLiVNlzxRSRl5JVVuHU9nA1x8EwIQAGUARQAZNwAeABUiWAAPSjAAEwgiEGEAK1hgYnZkMGdFdAgAR2hvILkAGiIAB2tbewheDP8AbUDfLtrnEYBdGZDtbCJlojhiLgBJQty3AEYllbW+WAB3eJa3ZugD5ZjiWDAfWGL2AHlyyoJ4B6eIdF7UDY7AwIDgViRjMQ0KgrIDBC8iLNcODaCAMHdEREugA3ZDQfiweYgWjZR4yZ6YIiLcHgjEAoH2NykciUWEMhhOZzoCJgmm3SFEMhyHbsMCnIg0OQAURy3X+fWBqC6AHI5MreXyMVwGA9mEyzJQaPRGMxOHQtgVcjgbjSxWcLqLTudoPAyN1oMhTULcl1tSbYNa+ctoWz4fBuvwIAALdC4-EBm3gzbbHIAalTNr0yJWZAI-FQYERdudk1QML6EBm2Cz2Fk9lonpYoeK1JWYCBbV8NrRltQvGVAEF4gBhZVEAA+RGVABEpSPlTboNJBNICLwBCIGNXcAB6HdECJ8IFEWREWjSVAmbogCCr6TgIyEHoV3a8ZtuVvLdu2fuCZA5ZUOm7VBe37IdRyA8ElxXNciF2AAGICaz3A8XCPWwT0LD0rxvO8HzpCsACY3wrD9gNAqdwMAxdl1XXgEMgtsOynP8AKQ6IBSuNxDHBCBYDgKoiETFYACpGL5bhoNXIghxPfIIAAfW6BglOQYUbVoVAQEEISgyIAhkGEOBdJWE4ox1Ey+TAbSWHYbhv1gciGCIYRXAcohuB7LcoNo4hJN87BDEfEwyAgfhoAIXY3DiJJkjSZsGiuLp6XhXYcC1Z5woIQjooSFJ4orRKWmSojrRiGAEGgEA5HQZUqDnABVZIsl2dVgoq+Aqpq0KsrS9q4E66ravq+ImqyQi2vKgautqgBZEACmkWhnF8fTzMFTKIqIApwDUZViGEMx3ACC5UVQbaZGxZzr0kORQsm4wOpmnqIsIzAgA const createReference = (ref: number): string => `\$${ref}` const createParameterKey = (key: string): string => `:${key}` -
max10rogerio revised this gist
Mar 9, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const createReference = (ref: number): string => `\$${ref}` const createParameterKey = (key: string): string => `:${key}` const toSQL = <T extends object = any>(sql: string, parameters: T): [string, any[]] => { let refIndex = 1 let newSql = sql const entries = Object.entries(params) -
max10rogerio revised this gist
Mar 9, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // Example // https://www.typescriptlang.org/play?#code/MYewdgziA2CmB0w4EMBOAKAlAKG6SALgATCqzIGwBKsAZrGWMLEQLxHpm0BcRYArgFsARg0y8IBVAEswAczYA+IgAMAOgBINAby4BfFXnCSSZCrAAKaZINiVUAaVgBPNhwDWLiVNlzxRSRl5JVVuHU9nA1x8EwIQAGUARQAZNwAeABUiWAAPSjAAEwgiEGEAK1hgYnZkMGdFdAgAR2hvILkAGiIAB2tbewheDP8AbUDfLv4wdzAQAHcwEYBdJZDtbCJNojhiLgBJQty3AEYNrZ2+WDn4lrdm6DPNmOJYMB9YYvYAeXLKgnhXu8IOheqgbHYGBAcFsSMZiGhUFYwYJPkRlrgYbQQBhnmiIl0AG7IaD8WCrEC0bJvGQfTBEdYwmG40Hg+xuUjkShI1kMJzOdARaGMp5wohkORHdhgK5EGhyACiOW6IL6ENQXQA5HINULhbiuAxXsx2WZKDR6IxmJw6AcCrkcI9GdLrrcpVcbtB4GRutBkFbxbkugbLbAHcLNgjuSj4N1+BAABboIkk0OOmH7Q45ADUWcdegxWzIBH4qDAaOdHq6kb6ECW2Hz2Fk9lofpYUeKDK2YHBbV8juxdtQvA1AEF4gBhDVEAA+RA1ABF5RONY7oNJBNICLwBCIGPXcAB6A9ECJ8cFEWREWjSVAmbogCCb6TgIyEHo1468dtuTubbu2YdBGQHINQ6ftUEHYcx0nMCYTXDctyIY4AAYwIbI8TxcM9bAvMtfTvB8nxfZkawAJi-Gsf3AyC52g0DV3XTdeBQ2Cux7OcgJAtDolFe43EMGEIFgOAqiINMtgAKlY4VuHgzciDHC98ggAB9boGDU5AJUdWhUBAQQxPDIgCGQYQ4EMrY5njQ0LOFWYcPYbh-1gaiGCIYRXGcohuAHPc4MY4hZIC7BDFfEwyAgfhoAIY43DiJJkjSdsGnuLoWRRY4cH1D4ooIUi4oSFIkprFKWjSsiHRiGAEGgEA5HQDUqCXABVZIsmOHUwuq+BavqiLcsyrq4B6uqGqa+JWqyUjOqq4beoagBZEACmkWhnF8YzrLFHLoqIApwDUDViGEMx3ACW4sVQPaZAJNz70kOQIpm4xuvm-rotIzAgA const createReference = (ref: number): string => `\$${ref}` const createParameterKey = (key: string): string => `:${key}` -
max10rogerio created this gist
Mar 9, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ const createReference = (ref: number): string => `\$${ref}` const createParameterKey = (key: string): string => `:${key}` const toSQL = <T extends object = any>(sql: string, parameters: T): [string, unknown[]] => { let refIndex = 1 let newSql = sql const entries = Object.entries(params) const arrParams = [] for(const [key, value] of entries) { const parameter = createParameterKey(key) const regex = new RegExp(parameter, 'g') const reference = createReference(refIndex) newSql = newSql.replace(regex, reference) arrParams.push(value) refIndex++ } return [newSql, arrParams] }