Skip to content

1.0 beta: How to type drizzle? #5104

@MickL

Description

@MickL

Enhancement hasn't been filed before.

  • I have verified this enhancement I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Since Drizzle now wants relations rather than schema, how do we type the Drizzle object? I tried using typeof relations with no success, before it was working with typeof schema:

import { drizzle, type NeonDatabase } from 'drizzle-orm/neon-serverless';
import { relations } from '@myworkspace/db';

let db: NeonDatabase<typeof relations>; // <- Doesnt work with relations

export const useDb = (): NeonDatabase<typeof relations> => {
  if (!db) {
    db = drizzle('DATABASE_URL', {
      relations,
      casing: 'snake_case',
    });
  }

  return db;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions