-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query logging and the 'call' method
- Loading branch information
Showing
14 changed files
with
208 additions
and
46 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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ArrayItemType } from './type-utils.js' | ||
|
||
export const LOG_LEVELS = ['query'] as const | ||
export type LogLevel = ArrayItemType<typeof LOG_LEVELS> | ||
|
||
export class Log { | ||
#levels: Readonly<Record<LogLevel, boolean>> | ||
|
||
constructor(levels: ReadonlyArray<LogLevel>) { | ||
this.#levels = { | ||
query: levels.includes('query'), | ||
} | ||
} | ||
|
||
query(callback: (log: (message: string) => void) => void) { | ||
if (this.#levels.query) { | ||
callback(this.#query) | ||
} | ||
} | ||
|
||
#query(message: string) { | ||
console.log(`kysely:query: ${message}`) | ||
} | ||
} |
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,11 +1,15 @@ | ||
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' | ||
|
||
export function randomString(length: number) { | ||
let chars: string[] = new Array(length) | ||
let chars = '' | ||
|
||
for (let i = 0; i < length; ++i) { | ||
chars[i] = CHARS[Math.floor(Math.random() * CHARS.length)] | ||
chars += randomChar() | ||
} | ||
|
||
return chars.join('') | ||
return chars | ||
} | ||
|
||
function randomChar() { | ||
return CHARS[Math.floor(Math.random() * CHARS.length)] | ||
} |
Oops, something went wrong.