Home
Softono

Drizzle Query Logger

Open source MIT TypeScript
168
Stars
7
Forks
7
Issues
1
Watchers
8 months
Last Commit

 About Drizzle Query Logger

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.

Platforms

Web Self-hosted

Languages

TypeScript

Need Help Installing Drizzle Query Logger?

We provide expert installation service for this software. Our team will install, configure, and secure Drizzle Query Logger on your server. plans start at just $30.

Drizzle Query Logger

View on GitHub

🎨 drizzle-query-logger

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.

✨ Features

  • 🎨 Beautiful formatting with box-drawing characters and colors
  • πŸ” SQL syntax highlighting with keyword colorization
  • πŸ“Š Query type detection with specific colors and icons
  • 🏷️ Table name extraction and highlighting
  • πŸ“ Parameter formatting with type-specific colors
  • ⏰ Timestamps for each query
  • πŸ”’ Query numbering to track execution order
  • βš™οΈ Configurable logging output

πŸ“¦ Installation

npm install drizzle-query-logger
yarn add drizzle-query-logger
pnpm add drizzle-query-logger
bun add drizzle-query-logger

πŸ“Έ Before vs After

Before (Default Drizzle Logger)

Before - Default Drizzle Logger

After (Enhanced Query Logger)

After - Enhanced Query Logger

See the dramatic difference! The enhanced logger transforms plain SQL output into beautifully formatted, color-coded queries with syntax highlighting, icons, and structured parameter display.

πŸš€ Usage

Basic Usage

import { createClient } from '@libsql/client/sqlite3';
import { drizzle } from 'drizzle-orm/libsql';
import { EnhancedQueryLogger } from 'drizzle-query-logger';

const client = createClient({ url: ':memory:' });
export const db = drizzle(client, {
  logger: new EnhancedQueryLogger(),
});

// Your queries will now be beautifully logged!
const users = await db.select().from(usersTable);

With Custom Logger Function

import { EnhancedQueryLogger } from 'drizzle-query-logger';

const logger = new EnhancedQueryLogger({
  log: (message) => {
    // Send to your preferred logging service
    console.log(message);
    // or use your custom logger
    // winston.info(message);
    // pino.info(message);
  }
});

export const db = drizzle(client, { logger });

🎯 Query Types & Icons

The logger automatically detects and styles different query types:

Query Type Icon Color
SELECT πŸ” Green
INSERT πŸ“ Blue
UPDATE ✏️ Yellow
DELETE πŸ—‘οΈ Red
CREATE πŸ—οΈ Magenta
DROP πŸ’₯ Red
ALTER πŸ”§ Cyan
OTHER ⚑ White

πŸ› οΈ Configuration

Constructor Options

interface LoggerOptions {
  log?: (message: string) => void;
}
  • log: Custom logging function (default: console.log)

Example with Custom Configuration

const logger = new EnhancedQueryLogger({
  log: (message) => {
    // Custom logging logic
    if (process.env.NODE_ENV === 'development') {
      console.log(message);
    } else {
      // Send to logging service in production
      yourLoggingService.debug(message);
    }
  }
});

🎨 Color Scheme

The logger uses a carefully chosen color scheme for optimal readability:

  • Keywords: Blue (SELECT, FROM, WHERE, etc.)
  • Strings: Green
  • Numbers: Cyan
  • Booleans: Yellow
  • Objects: Magenta
  • Null values: Dimmed
  • Table names: Yellow
  • Framework elements: Gray with cyan accents

πŸ”§ TypeScript Support

This package is written in TypeScript and provides full type definitions. It implements Drizzle's Logger interface:

import type { Logger } from 'drizzle-orm/logger';

export class EnhancedQueryLogger implements Logger {
  logQuery(query: string, params: unknown[]): void;
}

πŸ“‹ Requirements

  • Node.js: 16+
  • TypeScript: 5+ (peer dependency)
  • Drizzle ORM: Compatible with all recent versions

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Built for the Drizzle ORM ecosystem.

⭐ Star History

Star History

Star History Chart