85 lines
2.5 KiB
Markdown
85 lines
2.5 KiB
Markdown
# 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) |