-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Francis Duvivier
committed
Nov 27, 2024
1 parent
ef416f2
commit 2b5643f
Showing
7 changed files
with
179 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import { getEntriesWithDefinedValues } from "@util/objectEntries"; | ||
import { join, raw } from "sql-template-tag"; | ||
|
||
const COLUMN_KEY_REGEX = /^[a-zA-Z_][a-zA-Z0-9_]*$/; | ||
|
||
export function assertValidColumKey(key: string): string { | ||
if (!COLUMN_KEY_REGEX.test(key)) { | ||
throw new Error("Invalid column key: " + key); | ||
} | ||
return key; | ||
} | ||
|
||
export function getInsertKeysAndValuesSql(user: Object) { | ||
const definedEntries = getEntriesWithDefinedValues(user); | ||
const keys = join(definedEntries.map(([key]) => raw(key))); // raw is ok here because these keys are checked against our typescript definitions by tsoa | ||
const keys = join( | ||
definedEntries.map(([key]) => raw(assertValidColumKey(key))) | ||
); | ||
const values = join(definedEntries.map(([, value]) => value)); | ||
return { keys, values }; | ||
} |
This file contains 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
Oops, something went wrong.