-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve & fix a number of things with table queries
- Log all queries - Add SELECT ... LIMIT - Add Select.queryOne - Fix INSERT ... ON CONFLICT DO UPDATE - Add support for EXCLUDED vars - Fix Table.select() overload precedence - Fix duplicate vars being sent - Fix some vars not being sent as vars when they should be - Fix raw iso strings being combined with query text instead of as string - Clean up logging
- Loading branch information
1 parent
56260f9
commit 1756670
Showing
9 changed files
with
191 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
function log (text: string): void; | ||
function log (prefix: string, text: string): void; | ||
function log (prefix: string, text?: string) { | ||
if (!process.env.DEBUG_PG) | ||
return; | ||
|
||
if (text === undefined) | ||
text = prefix, prefix = ""; | ||
|
||
// prefix = prefix ? prefix.slice(0, 20).trimEnd() + " " : prefix; // cap prefix length at 20 | ||
|
||
const maxLineLength = 150 - prefix.length; | ||
text = text.split("\n") | ||
.flatMap(line => { | ||
const lines = []; | ||
while (line.length > maxLineLength) { | ||
lines.push(line.slice(0, maxLineLength)); | ||
line = line.slice(maxLineLength); | ||
} | ||
lines.push(line.trimEnd()); | ||
return lines; | ||
}) | ||
.filter(line => line) | ||
.map((line, i) => i ? line.padStart(line.length + prefix.length, " ") : `${prefix}${line}`) | ||
.join("\n"); | ||
|
||
console.log(text); | ||
} | ||
|
||
export default log; | ||
|
||
let ansicolor: typeof import("ansicolor") | undefined; | ||
export function color (color: keyof typeof import("ansicolor"), text: string) { | ||
if (!ansicolor) { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
ansicolor = require("ansicolor"); | ||
// eslint-disable-next-line no-empty | ||
} catch { } | ||
|
||
if (!ansicolor) | ||
return text; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call | ||
return (ansicolor as any)[color](text) as string; | ||
} |
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
Oops, something went wrong.