0.35.0

drizzle-team/drizzle-orm0.35.0Oct 15, 2024by github-actions[bot]

AI Summary

This release fixes the unusable API from 0.34.0 by introducing a cleaner way to initialize Drizzle with connection strings directly. It also adds .orderBy() and .limit() functions to update/delete queries for SQLite and MySQL, along with a new drizzle.mock() function for type checking scenarios.

Key Highlights

  • Fixed the init Drizzle database API that was unusable in version 0.34.0
  • Added new .orderBy() and .limit() functions to update and delete statements for SQLite and MySQL
  • Introduced drizzle.mock() function for type checking without database calls
  • Upgraded TypeScript version to 5.6.3 in the codebase
  • Fixed bug with new $count API error when using @neondatabase/serverless

Breaking Changes

  • The old API from 0.34.0 passing client directly to drizzle() is now deprecated (will be removed in V1)
  • Autocomplete performance in connection params will degrade due to DatabaseDriver | ConnectionParams types collision

New Features

  • New .orderBy() and .limit() functions for update and delete query builders in SQLite and MySQL
  • New drizzle.mock() function for testing and type checking without actual database connections
  • Support for passing connection string directly to drizzle() (e.g., drizzle(process.env.DATABASE_URL))
  • Support for connection object with individual parameters (user, password, host, port, db)

Full Release Notes

# 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](https://github.com/drizzle-team/drizzle-orm/discussions/3097)

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
```ts
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

```ts
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**

```ts
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
```ts
const db = drizzle({} as any)
```

Now you can do this using a mock function
```ts
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

- [[BUG]: New $count API error with @neondatabase/serverless](https://github.com/drizzle-team/drizzle-orm/issues/3081)