0.0.9 • Published 8 months ago

@andyrmitchell/drizzle-dialect-types v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Drizzle Dialect Types (Ddt)

Simplify writing code that works with any database driver, while also allowing you to handle driver-specific logic by detecting the database dialect when needed.

Features

  • Database-Agnostic Function Parameters: Write functions that accept any supported database type.
  • Conditional Logic: Handle dialect-specific logic inside your functions using helper utilities.

Installation

npm install @andyrmitchell/drizzle-dialect-types

Usage

Writing Database-Agnostic Functions

Use the DdtDatabases type to write functions that accept any supported database driver, and handle conditional logic based on the database dialect:

import { DdtDatabases, isDdtDialectPg, isDdtDialectSqlite } from "drizzle-dialect-tools";

function processDatabase(db: DdtDatabases) {
    if (isDdtDialectPg(db)) {
        // Logic specific to PostgreSQL
        console.log("This is a PostgreSQL database. Execute PostgreSQL-specific logic here.");
    } else if (isDdtDialectSqlite(db)) {
        // Logic specific to SQLite
        console.log("This is a SQLite database. Execute SQLite-specific logic here.");
    } else {
        console.error("Unsupported database type.");
    }
}

Key Types

  • DdtDatabases: Union type for all supported database drivers.
  • PgDdtDatabases: Union type for PostgreSQL drivers.
  • SqliteDdtDatabases: Union type for SQLite drivers.

API

  • isDdtDialectPg(db: DdtDatabases): db is PgDdtDatabases: Checks if a database instance belongs to the PostgreSQL dialect.
  • isDdtDialectSqlite(db: DdtDatabases): db is SqliteDdtDatabases: Checks if a database instance belongs to the SQLite dialect.
0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago