Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed Aug 27, 2024
2 parents a600b46 + 8d10463 commit 6a1e0d3
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 34 deletions.
Binary file added public/images/dbos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 1 addition & 6 deletions src/components/LandingPage/Benchmark/Benchmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ const Benchmark = () => {
<div className={styles.header}>Performance</div>
<div className={styles.description}>
<div className={styles.description__line}>
Drizzle has always been fast, we just wanted you to have proper
benchmarks experience
</div>
<div>
Well, actually it&apos;s not that Drizzle is fast, Drizzle just
doesn&apos;t slow you down
Drizzle doesn&apos;t slow you down
</div>
</div>
<div className={styles.container}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Banner.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div id="banner" class="banner">
<div class="banner__content">
<a href="https://driz.link/sentry-merch" target="_blank" rel="nofollow noreferrer">We've made some merch with Sentry! Go get one →</a>
<a href="https://x.com/DrizzleORM/status/1826693369357369712" target="_blank" rel="nofollow noreferrer">We've updated benchmarks, Drizzle's fast 🚀 →</a>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/content/documentation/docs/batch-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Tabs from '@components/markdown/Tabs.astro';
# Batch API

**LibSQL Batch API 解释**
_[来源](https://docs.turso.tech/reference/client-access#batches)_
_[来源](https://docs.turso.tech/sdk/ts/reference#batch-transactions)_

> 使用 libSQL 客户端库,批量是按顺序执行的一个或多个 SQL 语句,位于隐式事务中。
事务由 libSQL 后端控制。如果所有语句都成功,事务将提交。如果任何语句失败,整个事务将回滚,不会进行任何更改。
Expand Down
10 changes: 5 additions & 5 deletions src/content/documentation/docs/column-types/pg.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ import { varchar, pgTable } from "drizzle-orm/pg-core";

export const table = pgTable('table', {
varchar1: varchar('varchar1'),
varchar1: varchar('varchar2', { length: 256 }),
varchar2: varchar('varchar2', { length: 256 }),
});

// 将被推断为 text: "value1" | "value2" | null
Expand Down Expand Up @@ -820,8 +820,8 @@ import { integer, timestamp, text, pgTable } from "drizzle-orm/pg-core";

const table = pgTable('table', {
updateCounter: integer('update_counter').default(sql`1`).$onUpdateFn((): SQL => sql`${table.update_counter} + 1`),
updatedAt: timestamp('updated_at', { mode: 'date', precision: 3 }).$onUpdate(() => new Date()),
alwaysNull: text('always_null').$type<string | null>().$onUpdate(() => null),
updatedAt: timestamp('updated_at', { mode: 'date', precision: 3 }).$onUpdate(() => new Date()),
alwaysNull: text('always_null').$type<string | null>().$onUpdate(() => null),
});
```

Expand Down Expand Up @@ -850,7 +850,7 @@ CREATE TABLE IF NOT EXISTS "table" (
这要求值既唯一又不为 null。
<Section>
```typescript
import { integer, pgTable } from "drizzle-orm/pg-core";
import { serial, pgTable } from "drizzle-orm/pg-core";

const table = pgTable('table', {
id: serial('id').primaryKey(),
Expand All @@ -859,7 +859,7 @@ const table = pgTable('table', {

```sql
CREATE TABLE IF NOT EXISTS "table" (
"integer" serial PRIMARY KEY NOT NULL,
"id" serial PRIMARY KEY NOT NULL,
);
```
</Section>
11 changes: 11 additions & 0 deletions src/content/documentation/docs/get-started-postgresql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ const db = drizzle(pool)

const result = await db.select().from(...);
```
<Callout type="warning" emoji="⚙️">
Additional configuration is required to use WebSockets in environments where the `WebSocket` global is not defined, such as Node.js.

Add the `ws` and `bufferutil` packages to your project's dependencies, and set the `webSocketConstructor` config prior to creating a `Client` or `Pool` instance.

```typescript
import { Pool, neonConfig } from '@neondatabase/serverless';
import ws from 'ws';
neonConfig.webSocketConstructor = ws;
```
</Callout>
</Tab>
</Tabs>

Expand Down
5 changes: 3 additions & 2 deletions src/content/documentation/docs/get-started-sqlite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ node_compat = true
binding = "DB"
database_name = "YOUR DB NAME"
database_id = "YOUR DB ID"
migrations_dir = "drizzle/migrations"
```

初始化本地数据库并在本地运行服务器:
```bash
wrangler d1 execute <DATABASE_NAME> --local --file=./drizzle/0000_short_lockheed.sql
wrangler d1 migrations apply <DATABASE_NAME> --local
wrangler dev ## 在版本低于 3.0.0 的 wrangler 加上 --local 和 --persist 标志
```

Expand Down Expand Up @@ -550,4 +551,4 @@ const users = sqliteTable('users', {
intModifiers: integer('int_modifiers', { mode: 'boolean' }).notNull().default(false),
});
```
有关列类型的更多详细信息,请参阅 [Drizzle 中的 SQLite 列类型](/docs/column-types/sqlite)
有关列类型的更多详细信息,请参阅 [Drizzle 中的 SQLite 列类型](/docs/column-types/sqlite)
3 changes: 2 additions & 1 deletion src/content/documentation/docs/graphql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import Npm from '@components/markdown/Npm.astro';
```ts copy {1, 10}
import { buildSchema } from 'drizzle-graphql';
import { drizzle } from 'drizzle-orm/...';
import client from './db';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';

import * as dbSchema from './schema';

const db = drizzle({ schema: dbSchema });
const db = drizzle(client, { schema: dbSchema });

const { schema } = buildSchema(db);

Expand Down
4 changes: 2 additions & 2 deletions src/content/documentation/docs/indexes-constraints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,11 @@ Drizzle ORM 提供了几种声明外键的方法。
userLastName: text("user_last_name"),
}, (table) => {
return {
userReference: foreignKey(() => ({
userReference: foreignKey({
columns: [table.userFirstName, table.userLastName],
foreignColumns: [user.firstName, user.lastName],
name: "custom_name"
}))
})
}
});
```
Expand Down
10 changes: 5 additions & 5 deletions src/content/documentation/docs/joins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ Drizzle ORM 支持表别名,这在您需要进行自连接时非常有用。
```typescript copy
import { user } from "./schema";

const parent = alias(user, "parent")
const parent = aliasedTable(user, "parent")
const result = db
.select()
.from(user)
.leftJoin(parent, eq(parent.id, user.id));
.leftJoin(parent, eq(parent.id, user.parentId));
```
```sql
select ... from "user" left join "user" "parent" on "parent"."id" = "user"."id"
select ... from "user" left join "user" "parent" on "parent"."id" = "user"."parent_id"
```
```typescript
// result type
Expand Down Expand Up @@ -242,8 +242,8 @@ Drizzle ORM 从驱动程序中提供名称映射的结果,而不改变结构

您可以自由地以您想要的方式操作结果,这里是一个映射一对多关系数据的示例:
```typescript
type User = typeof usersTable.$inferSelect;
type Pet = typeof usersTable.$inferSelect;
type User = typeof users.$inferSelect;
type Pet = typeof pets.$inferSelect;

const rows = db.select({
user: users,
Expand Down
4 changes: 2 additions & 2 deletions src/content/documentation/docs/operators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ SELECT * FROM table WHERE EXISTS (SELECT * from table2)

<Section>
```typescript
import { exists } from "drizzle-orm";
import { notExists } from "drizzle-orm";

const query = db.select().from(table2)
db.select().from(table).where(notExists(query));
Expand Down Expand Up @@ -500,4 +500,4 @@ const overlaps = await db.select({ id: posts.id }).from(posts)
```sql
select "id" from "posts" where "posts"."tags" && {Typescript,ORM}
```
</Section>
</Section>
2 changes: 1 addition & 1 deletion src/content/documentation/docs/perf-queries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Tabs from '@components/markdown/Tabs.astro';
# 查询性能
当涉及 **Drizzle** 时 — 我们是一个薄的 TypeScript 层,位于 SQL 之上,几乎没有额外开销,并且为了使其实际为 0,您可以利用我们的预处理语句 API。

**当您向数据库运行查询时,会发生几件事情:**
**当您在数据库上运行查询时,会发生几件事情:**
- 查询构建器的所有配置都被连接到 SQL 字符串中
- 该字符串和参数被发送到数据库驱动程序
- 驱动程序将 SQL 查询编译为二进制 SQL 可执行格式,并将其发送到数据库
Expand Down
4 changes: 4 additions & 0 deletions src/content/documentation/docs/rqb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ export const profileInfo = pgTable('profile_info', {
metadata: jsonb('metadata'),
});

export const profileInfoRelations = relations(profileInfo, ({ one }) => ({
user: one(users, { fields: [profileInfo.userId], references: [users.id] }),
}));

const user = await queryUserWithProfileInfo();
//____^? type { id: number, profileInfo: { ... } | null }
```
Expand Down
2 changes: 1 addition & 1 deletion src/content/documentation/docs/set-operations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -974,4 +974,4 @@ SQL 集合操作将多个查询块的结果合并为一个结果。 SQL 标准
</CodeTab>
</CodeTabs>
</Tab>
</Tabs>
</Tabs>
6 changes: 3 additions & 3 deletions src/content/documentation/docs/transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ await db.transaction(async (tx) => {

您可以将业务逻辑嵌入事务中,并在需要时回滚:

```ts copy {6}
```ts copy {7}
const db = drizzle(...)

await db.transaction(async (tx) => {
const [account] = await tx.select({ balance: accounts.balance }).from(accounts).where(eq(users.name, 'Dan'));
if (account.balance < 100) {
await tx.rollback()
return
// This throws an exception that rollbacks the transaction.
tx.rollback()
}

await tx.update(accounts).set({ balance: sql`${accounts.balance} - 100.00` }).where(eq(users.name, 'Dan'));
Expand Down
12 changes: 11 additions & 1 deletion src/content/documentation/docs/update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ await db.update(users)
.where(eq(users.name, 'Dan'));
```

您传递给 `update` 的对象应该具有与数据库架构中列名匹配的键。
对象中忽略 `undefined` 的值:要将列设置为 `null`,请传递 `null`
您可以将 SQL 作为值传递给更新对象,就像这样:

```typescript copy
await db.update(users)
.set({ updatedAt: sql`NOW()` })
.where(eq(users.name, 'Dan'));
```

### 带返回值的更新
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'SQLite': true, 'MySQL': false }} />
您可以在 PostgreSQL 和 SQLite 中更新一行并获取它回来:
Expand Down Expand Up @@ -49,4 +59,4 @@ update "products" set "cheap" = $1
where "products"."price" < (select * from "average_price")
returning "id"
```
</Section>
</Section>
2 changes: 1 addition & 1 deletion src/content/documentation/kit-docs/config-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ import { defineConfig } from 'drizzle-kit'

export default defineConfig({
dbCredentials: {
url: '', // 👈 this could also be a path to the local sqlite file
url: '', // 👈 this could also be a path to the local sqlite file using 'file:<<path>>'
}
})
```
Expand Down
2 changes: 1 addition & 1 deletion src/content/documentation/kit-docs/upgrade-21.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { defineConfig } from "drizzle-kit"

export default defineConfig({
dialect: "sqlite", // "postgresql" | "mysql"
driver: "turso" // 仅在使用 `aws-data-api`、`turso`、`d1-http`(WIP) 或 `expo` 时使用
driver: "turso", // 仅在使用 `aws-data-api`、`turso`、`d1-http`(WIP) 或 `expo` 时使用
dbCredentials: {
url: ""
}
Expand Down
2 changes: 1 addition & 1 deletion src/content/guides/limit-offset-pagination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ await withPagination(query.$dynamic(), asc(users.id));
要实现它,可以这样做:

```ts copy {10}
const getUsets = async (page = 1, pageSize = 10) => {
const getUsers = async (page = 1, pageSize = 10) => {
const sq = db
.select({ id: users.id })
.from(users)
Expand Down
15 changes: 15 additions & 0 deletions src/data/s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ export const sponsorsData: ISponsor[] = [
isActive: true,
imageType: ImageType.IMAGE,
},
{
tier: {
name: "$250 a month",
isOneTime: false,
},
sponsorEntity: {
__typename: "Organization",
login: "driz.link/dbos",
name: "DBOS",
avatarUrl: "/images/dbos.png",
},
createdAt: "2024-08-13T16:35:56Z",
isActive: true,
imageType: ImageType.IMAGE,
},
];

export default sponsorsData;
3 changes: 3 additions & 0 deletions src/data/shipping.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2024-08-19:
- We've updated <a href='https://x.com/DrizzleORM/status/1826693369357369712'>benchmarks</a> 🚀

2024-08-05:
- |
<a href='https://x.com/DrizzleORM/status/1820462321942036749'><b>Drizzle Gateway</b></a> closed alpha release 🎉
Expand Down

0 comments on commit 6a1e0d3

Please sign in to comment.