Skip to content

Commit 9d92118

Browse files
🎉 Initial Commit
0 parents  commit 9d92118

File tree

9 files changed

+850
-0
lines changed

9 files changed

+850
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store
35+
36+
dist

README.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# 🎨 drizzle-query-logger
2+
3+
A beautiful, enhanced logger for Drizzle ORM that transforms your SQL queries into visually appealing, color-coded output with syntax highlighting, icons, and detailed formatting.
4+
5+
## ✨ Features
6+
7+
- 🎨 **Beautiful formatting** with box-drawing characters and colors
8+
- 🔍 **SQL syntax highlighting** with keyword colorization
9+
- 📊 **Query type detection** with specific colors and icons
10+
- 🏷️ **Table name extraction** and highlighting
11+
- 📝 **Parameter formatting** with type-specific colors
12+
-**Timestamps** for each query
13+
- 🔢 **Query numbering** to track execution order
14+
- ⚙️ **Configurable** logging output
15+
16+
## 📦 Installation
17+
18+
```bash
19+
npm install drizzle-query-logger
20+
```
21+
22+
```bash
23+
yarn add drizzle-query-logger
24+
```
25+
26+
```bash
27+
pnpm add drizzle-query-logger
28+
```
29+
30+
```bash
31+
bun add drizzle-query-logger
32+
```
33+
34+
## 🚀 Usage
35+
36+
### Basic Usage
37+
38+
```typescript
39+
import Database from 'better-sqlite3';
40+
import { drizzle } from 'drizzle-orm/better-sqlite3';
41+
import { EnhancedQueryLogger } from 'drizzle-query-logger';
42+
43+
const client = new Database(':memory:');
44+
export const db = drizzle(client, {
45+
logger: new EnhancedQueryLogger(),
46+
});
47+
48+
// Your queries will now be beautifully logged!
49+
const users = await db.select().from(usersTable);
50+
```
51+
52+
### With Custom Logger Function
53+
54+
```typescript
55+
import { EnhancedQueryLogger } from 'drizzle-query-logger';
56+
57+
const logger = new EnhancedQueryLogger({
58+
log: (message) => {
59+
// Send to your preferred logging service
60+
console.log(message);
61+
// or use your custom logger
62+
// winston.info(message);
63+
// pino.info(message);
64+
}
65+
});
66+
67+
export const db = drizzle(client, { logger });
68+
```
69+
70+
### Example Output
71+
72+
When you run queries, you'll see beautifully formatted output like this:
73+
74+
```
75+
╭─ Database Query #1
76+
│ Time: 14:32:15
77+
│ 🔍 SELECT on users
78+
│ SQL: SELECT id, name, email FROM users WHERE age > 18
79+
├─ Parameters: $1: 18
80+
╰──────────────────────────────────────────────────────
81+
```
82+
83+
## 🎯 Query Types & Icons
84+
85+
The logger automatically detects and styles different query types:
86+
87+
| Query Type | Icon | Color |
88+
|------------|------|--------|
89+
| SELECT | 🔍 | Green |
90+
| INSERT | 📝 | Blue |
91+
| UPDATE | ✏️ | Yellow |
92+
| DELETE | 🗑️ | Red |
93+
| CREATE | 🏗️ | Magenta|
94+
| DROP | 💥 | Red |
95+
| ALTER | 🔧 | Cyan |
96+
| OTHER || White |
97+
98+
## 🛠️ Configuration
99+
100+
### Constructor Options
101+
102+
```typescript
103+
interface LoggerOptions {
104+
log?: (message: string) => void;
105+
}
106+
```
107+
108+
- **`log`**: Custom logging function (default: `console.log`)
109+
110+
### Example with Custom Configuration
111+
112+
```typescript
113+
const logger = new EnhancedQueryLogger({
114+
log: (message) => {
115+
// Custom logging logic
116+
if (process.env.NODE_ENV === 'development') {
117+
console.log(message);
118+
} else {
119+
// Send to logging service in production
120+
yourLoggingService.debug(message);
121+
}
122+
}
123+
});
124+
```
125+
126+
## 🎨 Color Scheme
127+
128+
The logger uses a carefully chosen color scheme for optimal readability:
129+
130+
- **Keywords**: Blue (SELECT, FROM, WHERE, etc.)
131+
- **Strings**: Green
132+
- **Numbers**: Cyan
133+
- **Booleans**: Yellow
134+
- **Objects**: Magenta
135+
- **Null values**: Dimmed
136+
- **Table names**: Yellow
137+
- **Framework elements**: Gray with cyan accents
138+
139+
## 🔧 TypeScript Support
140+
141+
This package is written in TypeScript and provides full type definitions. It implements Drizzle's `Logger` interface:
142+
143+
```typescript
144+
import type { Logger } from 'drizzle-orm/logger';
145+
146+
export class EnhancedQueryLogger implements Logger {
147+
logQuery(query: string, params: unknown[]): void;
148+
}
149+
```
150+
151+
## 📋 Requirements
152+
153+
- **Node.js**: 16+
154+
- **TypeScript**: 5+ (peer dependency)
155+
- **Drizzle ORM**: Compatible with all recent versions
156+
157+
## 🤝 Contributing
158+
159+
Contributions are welcome! Please feel free to submit a Pull Request.
160+
161+
## 📄 License
162+
163+
MIT License - see the [LICENSE](LICENSE) file for details.
164+
165+
## 🙏 Acknowledgments
166+
167+
Built for the [Drizzle ORM](https://orm.drizzle.team/) ecosystem.

0 commit comments

Comments
 (0)