@logtape/drizzle-orm 1.3.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +109 -0
- package/deno.json +34 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/mod.cjs +148 -0
- package/dist/mod.d.cts +121 -0
- package/dist/mod.d.cts.map +1 -0
- package/dist/mod.d.ts +121 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +145 -0
- package/dist/mod.js.map +1 -0
- package/package.json +68 -0
- package/src/mod.test.ts +632 -0
- package/src/mod.ts +188 -0
- package/tsdown.config.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024–2025 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<!-- deno-fmt-ignore-file -->
|
|
2
|
+
|
|
3
|
+
@logtape/drizzle-orm
|
|
4
|
+
====================
|
|
5
|
+
|
|
6
|
+
[![JSR][JSR badge]][JSR]
|
|
7
|
+
[![npm][npm badge]][npm]
|
|
8
|
+
|
|
9
|
+
*@logtape/drizzle-orm* is a [Drizzle ORM] adapter that allows you to use
|
|
10
|
+
[LogTape] as Drizzle's logging backend for database query logging. This
|
|
11
|
+
enables seamless integration between Drizzle ORM applications and LogTape's
|
|
12
|
+
structured logging capabilities.
|
|
13
|
+
|
|
14
|
+
[JSR]: https://jsr.io/@logtape/drizzle-orm
|
|
15
|
+
[JSR badge]: https://jsr.io/badges/@logtape/drizzle-orm
|
|
16
|
+
[npm]: https://www.npmjs.com/package/@logtape/drizzle-orm
|
|
17
|
+
[npm badge]: https://img.shields.io/npm/v/@logtape/drizzle-orm?logo=npm
|
|
18
|
+
[LogTape]: https://logtape.org/
|
|
19
|
+
[Drizzle ORM]: https://orm.drizzle.team/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Installation
|
|
23
|
+
------------
|
|
24
|
+
|
|
25
|
+
~~~~ sh
|
|
26
|
+
deno add jsr:@logtape/drizzle-orm # for Deno
|
|
27
|
+
npm add @logtape/drizzle-orm # for npm
|
|
28
|
+
pnpm add @logtape/drizzle-orm # for pnpm
|
|
29
|
+
yarn add @logtape/drizzle-orm # for Yarn
|
|
30
|
+
bun add @logtape/drizzle-orm # for Bun
|
|
31
|
+
~~~~
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Usage
|
|
35
|
+
-----
|
|
36
|
+
|
|
37
|
+
~~~~ typescript
|
|
38
|
+
import { configure, getConsoleSink } from "@logtape/logtape";
|
|
39
|
+
import { getLogger } from "@logtape/drizzle-orm";
|
|
40
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
41
|
+
import postgres from "postgres";
|
|
42
|
+
|
|
43
|
+
await configure({
|
|
44
|
+
sinks: { console: getConsoleSink() },
|
|
45
|
+
loggers: [
|
|
46
|
+
{ category: ["drizzle-orm"], sinks: ["console"], lowestLevel: "debug" }
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const client = postgres(process.env.DATABASE_URL!);
|
|
51
|
+
const db = drizzle(client, {
|
|
52
|
+
logger: getLogger(),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Now all database queries will be logged through LogTape
|
|
56
|
+
~~~~
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
Custom category
|
|
60
|
+
---------------
|
|
61
|
+
|
|
62
|
+
You can specify a custom category for the logger:
|
|
63
|
+
|
|
64
|
+
~~~~ typescript
|
|
65
|
+
const db = drizzle(client, {
|
|
66
|
+
logger: getLogger({
|
|
67
|
+
category: ["myapp", "database"],
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
~~~~
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
Custom log level
|
|
74
|
+
----------------
|
|
75
|
+
|
|
76
|
+
By default, queries are logged at the `debug` level. You can change this:
|
|
77
|
+
|
|
78
|
+
~~~~ typescript
|
|
79
|
+
const db = drizzle(client, {
|
|
80
|
+
logger: getLogger({
|
|
81
|
+
level: "info",
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
~~~~
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
Structured logging
|
|
88
|
+
------------------
|
|
89
|
+
|
|
90
|
+
The adapter logs queries with structured data that includes:
|
|
91
|
+
|
|
92
|
+
- `formattedQuery`: The query with parameter placeholders (e.g., `$1`, `$2`)
|
|
93
|
+
replaced with actual values for easier reading
|
|
94
|
+
- `query`: The original query string with placeholders
|
|
95
|
+
- `params`: The original parameters array
|
|
96
|
+
|
|
97
|
+
This allows you to:
|
|
98
|
+
|
|
99
|
+
- Get human-readable output with text formatters
|
|
100
|
+
- Get machine-parseable output with JSON Lines formatter
|
|
101
|
+
- Use full query and params data with OpenTelemetry, Sentry, and other sinks
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
Docs
|
|
105
|
+
----
|
|
106
|
+
|
|
107
|
+
The docs of this package is available at
|
|
108
|
+
<https://logtape.org/manual/integrations#drizzle-orm>.
|
|
109
|
+
For the API references, see <https://jsr.io/@logtape/drizzle-orm/doc>.
|
package/deno.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@logtape/drizzle-orm",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": "./src/mod.ts",
|
|
6
|
+
"exclude": [
|
|
7
|
+
"coverage/",
|
|
8
|
+
"npm/",
|
|
9
|
+
"dist/"
|
|
10
|
+
],
|
|
11
|
+
"tasks": {
|
|
12
|
+
"build": "pnpm build",
|
|
13
|
+
"test": "deno test --allow-env --allow-sys --allow-net",
|
|
14
|
+
"test:node": {
|
|
15
|
+
"dependencies": [
|
|
16
|
+
"build"
|
|
17
|
+
],
|
|
18
|
+
"command": "node --experimental-transform-types --test"
|
|
19
|
+
},
|
|
20
|
+
"test:bun": {
|
|
21
|
+
"dependencies": [
|
|
22
|
+
"build"
|
|
23
|
+
],
|
|
24
|
+
"command": "bun test"
|
|
25
|
+
},
|
|
26
|
+
"test-all": {
|
|
27
|
+
"dependencies": [
|
|
28
|
+
"test",
|
|
29
|
+
"test:node",
|
|
30
|
+
"test:bun"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
|
|
3
|
+
|
|
4
|
+
//#region src/mod.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Drizzle ORM-compatible logger that wraps LogTape.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { drizzle } from "drizzle-orm/postgres-js";
|
|
11
|
+
* import { getLogger } from "@logtape/drizzle-orm";
|
|
12
|
+
* import postgres from "postgres";
|
|
13
|
+
*
|
|
14
|
+
* const client = postgres(process.env.DATABASE_URL!);
|
|
15
|
+
* const db = drizzle(client, {
|
|
16
|
+
* logger: getLogger(),
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @since 1.3.0
|
|
21
|
+
*/
|
|
22
|
+
var DrizzleLogger = class {
|
|
23
|
+
#logger;
|
|
24
|
+
#level;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new DrizzleLogger instance.
|
|
27
|
+
* @param logger The LogTape logger to use.
|
|
28
|
+
* @param level The log level to use for query logging.
|
|
29
|
+
*/
|
|
30
|
+
constructor(logger, level = "debug") {
|
|
31
|
+
this.#logger = logger;
|
|
32
|
+
this.#level = level;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Logs a database query with its parameters.
|
|
36
|
+
*
|
|
37
|
+
* The log output includes:
|
|
38
|
+
* - `formattedQuery`: The query with parameter placeholders replaced with
|
|
39
|
+
* actual values (for readability)
|
|
40
|
+
* - `query`: The original query string with placeholders
|
|
41
|
+
* - `params`: The original parameters array
|
|
42
|
+
*
|
|
43
|
+
* @param query The SQL query string with parameter placeholders.
|
|
44
|
+
* @param params The parameter values.
|
|
45
|
+
*/
|
|
46
|
+
logQuery(query, params) {
|
|
47
|
+
const stringifiedParams = params.map(serialize);
|
|
48
|
+
const formattedQuery = query.replace(/\$(\d+)/g, (match) => {
|
|
49
|
+
const index = Number.parseInt(match.slice(1), 10);
|
|
50
|
+
return stringifiedParams[index - 1] ?? match;
|
|
51
|
+
});
|
|
52
|
+
const logMethod = this.#logger[this.#level].bind(this.#logger);
|
|
53
|
+
logMethod("Query: {formattedQuery}", {
|
|
54
|
+
formattedQuery,
|
|
55
|
+
query,
|
|
56
|
+
params
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Serializes a parameter value to a SQL-safe string representation.
|
|
62
|
+
*
|
|
63
|
+
* @param value The value to serialize.
|
|
64
|
+
* @returns The serialized string representation.
|
|
65
|
+
* @since 1.3.0
|
|
66
|
+
*/
|
|
67
|
+
function serialize(value) {
|
|
68
|
+
if (typeof value === "undefined" || value === null) return "NULL";
|
|
69
|
+
if (typeof value === "string") return stringLiteral(value);
|
|
70
|
+
if (typeof value === "number" || typeof value === "bigint") return value.toString();
|
|
71
|
+
if (typeof value === "boolean") return value ? "'t'" : "'f'";
|
|
72
|
+
if (value instanceof Date) return stringLiteral(value.toISOString());
|
|
73
|
+
if (Array.isArray(value)) return `ARRAY[${value.map(serialize).join(", ")}]`;
|
|
74
|
+
if (typeof value === "object") return stringLiteral(JSON.stringify(value));
|
|
75
|
+
return stringLiteral(String(value));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Converts a string to a SQL string literal with proper escaping.
|
|
79
|
+
*
|
|
80
|
+
* @param str The string to convert.
|
|
81
|
+
* @returns The escaped SQL string literal.
|
|
82
|
+
* @since 1.3.0
|
|
83
|
+
*/
|
|
84
|
+
function stringLiteral(str) {
|
|
85
|
+
if (/[\\'\n\r\t\b\f]/.test(str)) {
|
|
86
|
+
let escaped = str;
|
|
87
|
+
escaped = escaped.replaceAll("\\", "\\\\");
|
|
88
|
+
escaped = escaped.replaceAll("'", "\\'");
|
|
89
|
+
escaped = escaped.replaceAll("\n", "\\n");
|
|
90
|
+
escaped = escaped.replaceAll("\r", "\\r");
|
|
91
|
+
escaped = escaped.replaceAll(" ", "\\t");
|
|
92
|
+
escaped = escaped.replaceAll("\b", "\\b");
|
|
93
|
+
escaped = escaped.replaceAll("\f", "\\f");
|
|
94
|
+
return `E'${escaped}'`;
|
|
95
|
+
}
|
|
96
|
+
return `'${str}'`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Normalize category to array format.
|
|
100
|
+
*/
|
|
101
|
+
function normalizeCategory(category) {
|
|
102
|
+
return typeof category === "string" ? [category] : category;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a Drizzle ORM-compatible logger that wraps LogTape.
|
|
106
|
+
*
|
|
107
|
+
* @example Basic usage
|
|
108
|
+
* ```typescript
|
|
109
|
+
* import { drizzle } from "drizzle-orm/postgres-js";
|
|
110
|
+
* import { configure } from "@logtape/logtape";
|
|
111
|
+
* import { getLogger } from "@logtape/drizzle-orm";
|
|
112
|
+
* import postgres from "postgres";
|
|
113
|
+
*
|
|
114
|
+
* await configure({
|
|
115
|
+
* // ... LogTape configuration
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* const client = postgres(process.env.DATABASE_URL!);
|
|
119
|
+
* const db = drizzle(client, {
|
|
120
|
+
* logger: getLogger(),
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example With custom category and level
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const db = drizzle(client, {
|
|
127
|
+
* logger: getLogger({
|
|
128
|
+
* category: ["my-app", "database"],
|
|
129
|
+
* level: "info",
|
|
130
|
+
* }),
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @param options Configuration options for the logger.
|
|
135
|
+
* @returns A Drizzle ORM-compatible logger wrapping LogTape.
|
|
136
|
+
* @since 1.3.0
|
|
137
|
+
*/
|
|
138
|
+
function getLogger(options = {}) {
|
|
139
|
+
const category = normalizeCategory(options.category ?? ["drizzle-orm"]);
|
|
140
|
+
const logger = (0, __logtape_logtape.getLogger)(category);
|
|
141
|
+
return new DrizzleLogger(logger, options.level ?? "debug");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
exports.DrizzleLogger = DrizzleLogger;
|
|
146
|
+
exports.getLogger = getLogger;
|
|
147
|
+
exports.serialize = serialize;
|
|
148
|
+
exports.stringLiteral = stringLiteral;
|
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { LogLevel, LogLevel as LogLevel$1, Logger as Logger$1 } from "@logtape/logtape";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for configuring the Drizzle ORM LogTape logger.
|
|
7
|
+
* @since 1.3.0
|
|
8
|
+
*/
|
|
9
|
+
interface DrizzleLoggerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The LogTape category to use for logging.
|
|
12
|
+
* @default ["drizzle-orm"]
|
|
13
|
+
*/
|
|
14
|
+
readonly category?: string | readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* The log level to use for query logging.
|
|
17
|
+
* @default "debug"
|
|
18
|
+
*/
|
|
19
|
+
readonly level?: LogLevel$1;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Drizzle ORM's Logger interface.
|
|
23
|
+
* @since 1.3.0
|
|
24
|
+
*/
|
|
25
|
+
interface Logger {
|
|
26
|
+
logQuery(query: string, params: unknown[]): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A Drizzle ORM-compatible logger that wraps LogTape.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { drizzle } from "drizzle-orm/postgres-js";
|
|
34
|
+
* import { getLogger } from "@logtape/drizzle-orm";
|
|
35
|
+
* import postgres from "postgres";
|
|
36
|
+
*
|
|
37
|
+
* const client = postgres(process.env.DATABASE_URL!);
|
|
38
|
+
* const db = drizzle(client, {
|
|
39
|
+
* logger: getLogger(),
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @since 1.3.0
|
|
44
|
+
*/
|
|
45
|
+
declare class DrizzleLogger implements Logger {
|
|
46
|
+
#private;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new DrizzleLogger instance.
|
|
49
|
+
* @param logger The LogTape logger to use.
|
|
50
|
+
* @param level The log level to use for query logging.
|
|
51
|
+
*/
|
|
52
|
+
constructor(logger: Logger$1, level?: LogLevel$1);
|
|
53
|
+
/**
|
|
54
|
+
* Logs a database query with its parameters.
|
|
55
|
+
*
|
|
56
|
+
* The log output includes:
|
|
57
|
+
* - `formattedQuery`: The query with parameter placeholders replaced with
|
|
58
|
+
* actual values (for readability)
|
|
59
|
+
* - `query`: The original query string with placeholders
|
|
60
|
+
* - `params`: The original parameters array
|
|
61
|
+
*
|
|
62
|
+
* @param query The SQL query string with parameter placeholders.
|
|
63
|
+
* @param params The parameter values.
|
|
64
|
+
*/
|
|
65
|
+
logQuery(query: string, params: unknown[]): void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Serializes a parameter value to a SQL-safe string representation.
|
|
69
|
+
*
|
|
70
|
+
* @param value The value to serialize.
|
|
71
|
+
* @returns The serialized string representation.
|
|
72
|
+
* @since 1.3.0
|
|
73
|
+
*/
|
|
74
|
+
declare function serialize(value: unknown): string;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a string to a SQL string literal with proper escaping.
|
|
77
|
+
*
|
|
78
|
+
* @param str The string to convert.
|
|
79
|
+
* @returns The escaped SQL string literal.
|
|
80
|
+
* @since 1.3.0
|
|
81
|
+
*/
|
|
82
|
+
declare function stringLiteral(str: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Drizzle ORM-compatible logger that wraps LogTape.
|
|
85
|
+
*
|
|
86
|
+
* @example Basic usage
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { drizzle } from "drizzle-orm/postgres-js";
|
|
89
|
+
* import { configure } from "@logtape/logtape";
|
|
90
|
+
* import { getLogger } from "@logtape/drizzle-orm";
|
|
91
|
+
* import postgres from "postgres";
|
|
92
|
+
*
|
|
93
|
+
* await configure({
|
|
94
|
+
* // ... LogTape configuration
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* const client = postgres(process.env.DATABASE_URL!);
|
|
98
|
+
* const db = drizzle(client, {
|
|
99
|
+
* logger: getLogger(),
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example With custom category and level
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const db = drizzle(client, {
|
|
106
|
+
* logger: getLogger({
|
|
107
|
+
* category: ["my-app", "database"],
|
|
108
|
+
* level: "info",
|
|
109
|
+
* }),
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param options Configuration options for the logger.
|
|
114
|
+
* @returns A Drizzle ORM-compatible logger wrapping LogTape.
|
|
115
|
+
* @since 1.3.0
|
|
116
|
+
*/
|
|
117
|
+
declare function getLogger(options?: DrizzleLoggerOptions): DrizzleLogger;
|
|
118
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
119
|
+
//#endregion
|
|
120
|
+
export { DrizzleLogger, DrizzleLoggerOptions, LogLevel, Logger, getLogger, serialize, stringLiteral };
|
|
121
|
+
//# sourceMappingURL=mod.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAYA;AAkBA;AAqBA;AAA2B,UAvCV,oBAAA,CAuCU;EAAA;;;AAAiB;EAiD5B,SAAA,QAAS,CAAA,EAAA,MAAA,GAAA,SAAA,MAAA,EAAA;EAyBT;AA0DhB;;;EAA4D,SAAG,KAAA,CAAA,EAhK5C,UAgK4C;AAAa;;;;;UAzJ3D,MAAA;;;;;;;;;;;;;;;;;;;;cAqBJ,aAAA,YAAyB;;;;;;;sBAShB,kBAAsB;;;;;;;;;;;;;;;;;;;;;;iBAwC5B,SAAA;;;;;;;;iBAyBA,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0DA,SAAA,WAAmB,uBAA4B"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { LogLevel, LogLevel as LogLevel$1, Logger as Logger$1 } from "@logtape/logtape";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for configuring the Drizzle ORM LogTape logger.
|
|
7
|
+
* @since 1.3.0
|
|
8
|
+
*/
|
|
9
|
+
interface DrizzleLoggerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The LogTape category to use for logging.
|
|
12
|
+
* @default ["drizzle-orm"]
|
|
13
|
+
*/
|
|
14
|
+
readonly category?: string | readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* The log level to use for query logging.
|
|
17
|
+
* @default "debug"
|
|
18
|
+
*/
|
|
19
|
+
readonly level?: LogLevel$1;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Drizzle ORM's Logger interface.
|
|
23
|
+
* @since 1.3.0
|
|
24
|
+
*/
|
|
25
|
+
interface Logger {
|
|
26
|
+
logQuery(query: string, params: unknown[]): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A Drizzle ORM-compatible logger that wraps LogTape.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { drizzle } from "drizzle-orm/postgres-js";
|
|
34
|
+
* import { getLogger } from "@logtape/drizzle-orm";
|
|
35
|
+
* import postgres from "postgres";
|
|
36
|
+
*
|
|
37
|
+
* const client = postgres(process.env.DATABASE_URL!);
|
|
38
|
+
* const db = drizzle(client, {
|
|
39
|
+
* logger: getLogger(),
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @since 1.3.0
|
|
44
|
+
*/
|
|
45
|
+
declare class DrizzleLogger implements Logger {
|
|
46
|
+
#private;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new DrizzleLogger instance.
|
|
49
|
+
* @param logger The LogTape logger to use.
|
|
50
|
+
* @param level The log level to use for query logging.
|
|
51
|
+
*/
|
|
52
|
+
constructor(logger: Logger$1, level?: LogLevel$1);
|
|
53
|
+
/**
|
|
54
|
+
* Logs a database query with its parameters.
|
|
55
|
+
*
|
|
56
|
+
* The log output includes:
|
|
57
|
+
* - `formattedQuery`: The query with parameter placeholders replaced with
|
|
58
|
+
* actual values (for readability)
|
|
59
|
+
* - `query`: The original query string with placeholders
|
|
60
|
+
* - `params`: The original parameters array
|
|
61
|
+
*
|
|
62
|
+
* @param query The SQL query string with parameter placeholders.
|
|
63
|
+
* @param params The parameter values.
|
|
64
|
+
*/
|
|
65
|
+
logQuery(query: string, params: unknown[]): void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Serializes a parameter value to a SQL-safe string representation.
|
|
69
|
+
*
|
|
70
|
+
* @param value The value to serialize.
|
|
71
|
+
* @returns The serialized string representation.
|
|
72
|
+
* @since 1.3.0
|
|
73
|
+
*/
|
|
74
|
+
declare function serialize(value: unknown): string;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a string to a SQL string literal with proper escaping.
|
|
77
|
+
*
|
|
78
|
+
* @param str The string to convert.
|
|
79
|
+
* @returns The escaped SQL string literal.
|
|
80
|
+
* @since 1.3.0
|
|
81
|
+
*/
|
|
82
|
+
declare function stringLiteral(str: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Drizzle ORM-compatible logger that wraps LogTape.
|
|
85
|
+
*
|
|
86
|
+
* @example Basic usage
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { drizzle } from "drizzle-orm/postgres-js";
|
|
89
|
+
* import { configure } from "@logtape/logtape";
|
|
90
|
+
* import { getLogger } from "@logtape/drizzle-orm";
|
|
91
|
+
* import postgres from "postgres";
|
|
92
|
+
*
|
|
93
|
+
* await configure({
|
|
94
|
+
* // ... LogTape configuration
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* const client = postgres(process.env.DATABASE_URL!);
|
|
98
|
+
* const db = drizzle(client, {
|
|
99
|
+
* logger: getLogger(),
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example With custom category and level
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const db = drizzle(client, {
|
|
106
|
+
* logger: getLogger({
|
|
107
|
+
* category: ["my-app", "database"],
|
|
108
|
+
* level: "info",
|
|
109
|
+
* }),
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param options Configuration options for the logger.
|
|
114
|
+
* @returns A Drizzle ORM-compatible logger wrapping LogTape.
|
|
115
|
+
* @since 1.3.0
|
|
116
|
+
*/
|
|
117
|
+
declare function getLogger(options?: DrizzleLoggerOptions): DrizzleLogger;
|
|
118
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
119
|
+
//#endregion
|
|
120
|
+
export { DrizzleLogger, DrizzleLoggerOptions, LogLevel, Logger, getLogger, serialize, stringLiteral };
|
|
121
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAYA;AAkBA;AAqBA;AAA2B,UAvCV,oBAAA,CAuCU;EAAA;;;AAAiB;EAiD5B,SAAA,QAAS,CAAA,EAAA,MAAA,GAAA,SAAA,MAAA,EAAA;EAyBT;AA0DhB;;;EAA4D,SAAG,KAAA,CAAA,EAhK5C,UAgK4C;AAAa;;;;;UAzJ3D,MAAA;;;;;;;;;;;;;;;;;;;;cAqBJ,aAAA,YAAyB;;;;;;;sBAShB,kBAAsB;;;;;;;;;;;;;;;;;;;;;;iBAwC5B,SAAA;;;;;;;;iBAyBA,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0DA,SAAA,WAAmB,uBAA4B"}
|