github drizzle-team/drizzle-orm 0.35.0

latest releases: 0.35.1, drizzle-kit@0.26.2, drizzle-kit@0.26.1...
one day ago

Important change after 0.34.0 release

Updated the init Drizzle database API

The API from version 0.34.0 turned out to be unusable and needs to be changed. You can read more about our decisions in this discussion

If you still want to use the new API introduced in 0.34.0, which can create driver clients for you under the hood, you can now do so

import { drizzle } from "drizzle-orm/node-postgres";

const db = drizzle(process.env.DATABASE_URL);
// or
const db = drizzle({
  connection: process.env.DATABASE_URL
});
const db = drizzle({
  connection: {
    user: "...",
    password: "...",
    host: "...",
    port: 4321,
    db: "...",
  },
});

// if you need to pass logger or schema
const db = drizzle({
  connection: process.env.DATABASE_URL,
  logger: true,
  schema: schema,
});

in order to not introduce breaking change - we will still leave support for deprecated API until V1 release.
It will degrade autocomplete performance in connection params due to DatabaseDriver | ConnectionParams types collision,
but that's a decent compromise against breaking changes

import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";

const client = new Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle(client); // deprecated but available

// new version
const db = drizzle({
  client: client,
});

New Features

New .orderBy() and .limit() functions in update and delete statements SQLite and MySQL

You now have more options for the update and delete query builders in MySQL and SQLite

Example

await db.update(usersTable).set({ verified: true }).limit(2).orderBy(asc(usersTable.name));

await db.delete(usersTable).where(eq(usersTable.verified, false)).limit(1).orderBy(asc(usersTable.name));

New drizzle.mock() function

There were cases where you didn't need to provide a driver to the Drizzle object, and this served as a workaround

const db = drizzle({} as any)

Now you can do this using a mock function

const db = drizzle.mock()

There is no valid production use case for this, but we used it in situations where we needed to check types, etc., without making actual database calls or dealing with driver creation. If anyone was using it, please switch to using mocks now

Internal updates

  • Upgraded TS in codebase to the version 5.6.3

Bug fixes

Don't miss a new drizzle-orm release

NewReleases is sending notifications on new releases.