Skip to content

Commit

Permalink
Add notes about mysql datetime changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiSherman committed Sep 6, 2023
1 parent 01ea041 commit 6c516c3
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions changelogs/drizzle-orm/0.28.6.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
## Changes

> **Note**:
> MySQL `datetime` with `mode: 'date'` will now store dates in UTC strings and retrieve data in UTC as well to align with MySQL behavior for `datetime`. If you need a different behavior and want to handle `datetime` mapping in a different way, please use `mode: 'string'` or [Custom Types](https://orm.drizzle.team/docs/custom-types) implementation
Check [Fix Datetime mapping for MySQL](https://github.com/drizzle-team/drizzle-orm/pull/1082) for implementation details

## New Features

### 🎉 `LibSQL` batch api support
### 🎉 `LibSQL` batch api support

Reference: https://docs.turso.tech/reference/client-access/javascript-typescript-sdk#execute-a-batch-of-statements

Batch API usage example:

```ts
const batchResponse = await db.batch([
db.insert(usersTable).values({ id: 1, name: 'John' }).returning({ id: usersTable.id }),
db.insert(usersTable).values({ id: 1, name: 'John' }).returning({
id: usersTable.id,
}),
db.update(usersTable).set({ name: 'Dan' }).where(eq(usersTable.id, 1)),
db.query.usersTable.findMany({}),
db.select().from(usersTable).where(eq(usersTable.id, 1)),
db.select({ id: usersTable.id, invitedBy: usersTable.invitedBy }).from(usersTable),
db.select({ id: usersTable.id, invitedBy: usersTable.invitedBy }).from(
usersTable,
),
]);
```

Type for `batchResponse` in this example would be:

```ts
type BatchResponse = [
{
Expand All @@ -38,9 +51,11 @@ type BatchResponse = [
id: number;
invitedBy: number | null;
}[],
]
];
```

All possible builders that can be used inside `db.batch`:

```ts
`db.all()`,
`db.get()`,
Expand All @@ -62,7 +77,7 @@ Example

```ts
const test = sqliteTable('test', {
dataTyped: text('data_typed', { mode: 'json' }).$type<{ a: 1 }>().notNull(),
dataTyped: text('data_typed', { mode: 'json' }).$type<{ a: 1 }>().notNull(),
});
```

Expand All @@ -81,23 +96,25 @@ List of operators and usage examples

```ts
const contains = await db.select({ id: posts.id }).from(posts)
.where(arrayContains(posts.tags, ['Typescript', 'ORM']));
.where(arrayContains(posts.tags, ['Typescript', 'ORM']));

const contained = await db.select({ id: posts.id }).from(posts)
.where(arrayContained(posts.tags, ['Typescript', 'ORM']));
.where(arrayContained(posts.tags, ['Typescript', 'ORM']));

const overlaps = await db.select({ id: posts.id }).from(posts)
.where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']));
.where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']));

const withSubQuery = await db.select({ id: posts.id }).from(posts)
.where(arrayContains(
posts.tags,
db.select({ tags: posts.tags }).from(posts).where(eq(posts.id, 1)),
));
.where(arrayContains(
posts.tags,
db.select({ tags: posts.tags }).from(posts).where(eq(posts.id, 1)),
));
```

### 🎉 Add more SQL operators for where filter function in Relational Queries - thanks @cayter!

**Before**

```ts
import { inArray } from "drizzle-orm/pg-core";

Expand All @@ -107,6 +124,7 @@ await db.users.findFirst({
```

**After**

```ts
await db.users.findFirst({
where: (table, { inArray }) => inArray(table.id, [ ... ])
Expand Down

0 comments on commit 6c516c3

Please sign in to comment.