From 98acdb41b97c2733dd22469f62e47b96789cade3 Mon Sep 17 00:00:00 2001 From: Nin3 <30520689+Nin3lee@users.noreply.github.com> Date: Fri, 6 Sep 2024 18:05:28 +0800 Subject: [PATCH 1/7] (WIP): Update astro-db.mdx --- src/content/docs/zh-cn/guides/astro-db.mdx | 63 +++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/guides/astro-db.mdx b/src/content/docs/zh-cn/guides/astro-db.mdx index 533dae04bce4f..fdb95dd838769 100644 --- a/src/content/docs/zh-cn/guides/astro-db.mdx +++ b/src/content/docs/zh-cn/guides/astro-db.mdx @@ -38,7 +38,7 @@ Astro DB 是一款专为 Astro 设计的全托管 SQL 数据库。你可以在 ## 定义你的数据库 -Astro DB 是一个用于配置、开发和查询你的数据的完整解决方案。每当你运行 `astro dev` 时,都会创建一个本地数据库,并使用 LibSQL 来管理你的数据,而无需 Docker 或网络连接。 +Astro DB 是一个用于配置、开发和查询你的数据的完整解决方案。每当你运行 `astro dev` 时,都会创建一个本地数据库,并使用 libSQL 来管理你的数据,而无需 Docker 或网络连接。 使用 `astro add` 命令安装 `@astrojs/db` 将在你的项目中创建一个 `db/config.ts` 文件,你将在其中定义你的数据库表: @@ -653,6 +653,67 @@ astro dev --remote +## libSQL + +

+ +Astro DB 可以从任何公开 libSQL 服务器远程协议的平台,连接到任何 libSQL 服务器,或者也可以自托管。 + +要将 Astro DB 连接到 libSQL 数据库,需要设置以下环境变量: +- `ASTRO_DB_REMOTE_URL`: libSQL 服务器的连接 URL +- `ASTRO_DB_APP_TOKEN`: libSQL 服务器的身份验证令牌 + +使用 libSQL 时和连接到 Astro Studio 托管数据库时,[部署和推送更改](#使用-studio-连接进行部署)到数据库的命令是相同的。不过,当使用 `--remote` 选项运行命令,如 `astro build` 和 `astro db Push` 时,都需要在本地设置环境变量。 + +libSQL 连接的详细信息(例如加密密钥、备份、同步间隔)可以配置为远程连接 URL 中的查询参数。 + +例如,要让本地文件作为加密 libSQL 服务器的嵌入式副本,你可以设置以下环境变量: + +```dotenv title=".env" +ASTRO_DB_REMOTE_URL=file://local-copy.db?encryptionKey=your-encryption-key&syncInterval=60&syncUrl=libsql%3A%2F%2Fyour.server.io +ASTRO_DB_APP_TOKEN=token-to-your-remote-url +``` + +### URL 方案和 host + +libSQL 同时支持 HTTP 和 WebSockets 作为远程服务器的传输协议。它还支持使用本地文件或内存数据库。这些都可以在连接 URL 中使用以下 URL 方案来进行配置: + +- `memory:` 将使用内存数据库。在这种情况下,host 必须为空。 +- `file:` 将使用本地文件。host 是文件的路径(file:path/to/file.db)。 +- `libsql:` will use a remote server through the protocol preferred by the library (this might be different across versions). The host is the address of the server (`libsql://your.server.io`). +- `http:` will use a remote server through HTTP. `https:` can be used to enable a secure connection. The host is the same as for `libsql:`. +- `ws:` will use a remote server through WebSockets. `wss:` can be used to enable a secure connection. The host is the same as for `libsql:`. + +### `encryptionKey` + +libSQL has native support for encrypted databases. Passing this search parameter will enable encryption using the given key: + +```dotenv title=".env" +ASTRO_DB_REMOTE_URL=file:path/to/file.db?encryptionKey=your-encryption-key +``` + +### `syncUrl` + +Embedded replicas are a feature of libSQL clients that enables a full synchronized copy of your database on a local file or in memory for ultra-fast reads. Writes are sent to a remote database defined on the `syncUrl` and synchronized with the local copy. + +Use this property to pass a separate connection URL to turn the DB into an embedded replica of another database. This should only be used with the schemes `file:` and `memory:`. The parameter must be URL encoded. + +For example, to have an in-memory embedded replica of a database on `libsql://your.server.io`, you can set the connection URL as such: + +```dotenv title=".env" +ASTRO_DB_REMOTE_URL=memory:?syncUrl=libsql%3A%2F%2Fyour.server.io +``` + +### `syncInterval` + +Interval between embedded replicas synchronizations in seconds. By default it only synchronizes on startup and after writes. + +This property is only used when `syncUrl` is also set. For example, to set an in-memory embedded replica to synchronize every minute set the following environment variable: + +```dotenv title=".env" +ASTRO_DB_REMOTE_URL=memory:?syncUrl=libsql%3A%2F%2Fyour.server.io&syncInterval=60 +``` + ## 构建 Astro DB 集成 [Astro 集成](/zh-cn/reference/integrations-reference/) 可以通过额外的 Astro DB 表和填充数据来扩展用户项目。 From 1c1cdcdaf3c4d04d5ab06181e78414c338bccff6 Mon Sep 17 00:00:00 2001 From: Nin3 <30520689+Nin3lee@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:08:45 +0800 Subject: [PATCH 2/7] i18n(zh-cn): Update `astro-db.mdx` --- src/content/docs/zh-cn/guides/astro-db.mdx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/content/docs/zh-cn/guides/astro-db.mdx b/src/content/docs/zh-cn/guides/astro-db.mdx index fdb95dd838769..b52aa36b67e62 100644 --- a/src/content/docs/zh-cn/guides/astro-db.mdx +++ b/src/content/docs/zh-cn/guides/astro-db.mdx @@ -679,14 +679,15 @@ ASTRO_DB_APP_TOKEN=token-to-your-remote-url libSQL 同时支持 HTTP 和 WebSockets 作为远程服务器的传输协议。它还支持使用本地文件或内存数据库。这些都可以在连接 URL 中使用以下 URL 方案来进行配置: - `memory:` 将使用内存数据库。在这种情况下,host 必须为空。 -- `file:` 将使用本地文件。host 是文件的路径(file:path/to/file.db)。 +- `file:` 将使用本地文件。host 是文件的路径(`file:path/to/file.db`)。 - `libsql:` will use a remote server through the protocol preferred by the library (this might be different across versions). The host is the address of the server (`libsql://your.server.io`). -- `http:` will use a remote server through HTTP. `https:` can be used to enable a secure connection. The host is the same as for `libsql:`. -- `ws:` will use a remote server through WebSockets. `wss:` can be used to enable a secure connection. The host is the same as for `libsql:`. +- `libsql:` 将通过库首选的协议使用远程服务器(可能因版本而异)。host 是服务器的地址(`libsql://your.server.io`)。 +- `http:` 将通过 HTTP 使用远程服务器。`https:` 可用于启用安全连接。host 和 `libsql` 相同。 +- `ws:` 将通过 WebSockets 使用远程服务器。`wss:` 可用于启用安全连接。 host 和 `libsql` 相同。 -### `encryptionKey` +### `加密密钥` -libSQL has native support for encrypted databases. Passing this search parameter will enable encryption using the given key: +libSQL 对加密数据库具有原生支持。传递此搜索参数将使用给定密钥的加密: ```dotenv title=".env" ASTRO_DB_REMOTE_URL=file:path/to/file.db?encryptionKey=your-encryption-key @@ -694,11 +695,11 @@ ASTRO_DB_REMOTE_URL=file:path/to/file.db?encryptionKey=your-encryption-key ### `syncUrl` -Embedded replicas are a feature of libSQL clients that enables a full synchronized copy of your database on a local file or in memory for ultra-fast reads. Writes are sent to a remote database defined on the `syncUrl` and synchronized with the local copy. +嵌入式副本是 libSQL 客户端的一项功能,可在本地文件或内存中实现数据库的完整同步副本,以实现超快读取。写入将发送到在 `syncUrl` 上定义的远程数据库并与本地副本同步。 -Use this property to pass a separate connection URL to turn the DB into an embedded replica of another database. This should only be used with the schemes `file:` and `memory:`. The parameter must be URL encoded. +使用此属性来传递单独的连接 URL,并将 DB 转换为另一个数据库的嵌入式副本。此属性只应与 `file:` 和 `memory:` 方案来一起使用。该参数必须经过 URL 编码。 -For example, to have an in-memory embedded replica of a database on `libsql://your.server.io`, you can set the connection URL as such: +例如,要在 `libsql://your.server.io` 上拥有数据库的内存嵌入式副本,你可以按如下方式设置连接 URL: ```dotenv title=".env" ASTRO_DB_REMOTE_URL=memory:?syncUrl=libsql%3A%2F%2Fyour.server.io @@ -706,9 +707,9 @@ ASTRO_DB_REMOTE_URL=memory:?syncUrl=libsql%3A%2F%2Fyour.server.io ### `syncInterval` -Interval between embedded replicas synchronizations in seconds. By default it only synchronizes on startup and after writes. +嵌入式副本同步之间的时间间隔(以秒为单位)。默认情况下,它仅在启动时和写入后同步。 -This property is only used when `syncUrl` is also set. For example, to set an in-memory embedded replica to synchronize every minute set the following environment variable: +此属性仅在同时设置了 `syncUrl` 时才生效。例如,要将内存中嵌入式副本设置为每分钟同步,请设置以下环境变量: ```dotenv title=".env" ASTRO_DB_REMOTE_URL=memory:?syncUrl=libsql%3A%2F%2Fyour.server.io&syncInterval=60 From 1e2f7804072c496cbb0d1f0c90c6c050ce0cf1c1 Mon Sep 17 00:00:00 2001 From: Nin3 <30520689+Nin3lee@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:11:33 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=90=8D=E4=B8=BA=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/content/docs/zh-cn/guides/astro-db.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/guides/astro-db.mdx b/src/content/docs/zh-cn/guides/astro-db.mdx index b52aa36b67e62..495dfcd9263a8 100644 --- a/src/content/docs/zh-cn/guides/astro-db.mdx +++ b/src/content/docs/zh-cn/guides/astro-db.mdx @@ -685,7 +685,7 @@ libSQL 同时支持 HTTP 和 WebSockets 作为远程服务器的传输协议。 - `http:` 将通过 HTTP 使用远程服务器。`https:` 可用于启用安全连接。host 和 `libsql` 相同。 - `ws:` 将通过 WebSockets 使用远程服务器。`wss:` 可用于启用安全连接。 host 和 `libsql` 相同。 -### `加密密钥` +### `encryptionKey` libSQL 对加密数据库具有原生支持。传递此搜索参数将使用给定密钥的加密: From 1e0f6a02342ad3f28aa2662c0416efec4f36be2a Mon Sep 17 00:00:00 2001 From: Nin3 <30520689+Nin3lee@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:04:46 +0800 Subject: [PATCH 4/7] fix: import `Since` component --- src/content/docs/zh-cn/guides/astro-db.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/content/docs/zh-cn/guides/astro-db.mdx b/src/content/docs/zh-cn/guides/astro-db.mdx index 495dfcd9263a8..c475cbf20e1c3 100644 --- a/src/content/docs/zh-cn/guides/astro-db.mdx +++ b/src/content/docs/zh-cn/guides/astro-db.mdx @@ -7,6 +7,7 @@ i18nReady: true import { FileTree } from '@astrojs/starlight/components'; import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'; import ReadMore from '~/components/ReadMore.astro'; +import Since from '~/components/Since.astro'; import StudioHeading from '~/components/StudioHeading.astro'; import { Steps } from '@astrojs/starlight/components'; From 1b3ded1c0b90277d046e8fe836edaf7a6dff6ca7 Mon Sep 17 00:00:00 2001 From: Nin3 <30520689+Nin3lee@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:00:27 +0800 Subject: [PATCH 5/7] Update src/content/docs/zh-cn/guides/astro-db.mdx Co-authored-by: liruifengv --- src/content/docs/zh-cn/guides/astro-db.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/guides/astro-db.mdx b/src/content/docs/zh-cn/guides/astro-db.mdx index c475cbf20e1c3..63dd4cc0a754b 100644 --- a/src/content/docs/zh-cn/guides/astro-db.mdx +++ b/src/content/docs/zh-cn/guides/astro-db.mdx @@ -664,7 +664,7 @@ Astro DB 可以从任何公开 libSQL 服务器远程协议的平台,连接到 - `ASTRO_DB_REMOTE_URL`: libSQL 服务器的连接 URL - `ASTRO_DB_APP_TOKEN`: libSQL 服务器的身份验证令牌 -使用 libSQL 时和连接到 Astro Studio 托管数据库时,[部署和推送更改](#使用-studio-连接进行部署)到数据库的命令是相同的。不过,当使用 `--remote` 选项运行命令,如 `astro build` 和 `astro db Push` 时,都需要在本地设置环境变量。 +使用 libSQL 时和连接到 Astro Studio 托管数据库时,[部署和推送更改](#使用-studio-连接进行部署)到数据库的命令是相同的。不过,当使用 `--remote` 选项运行命令,如 `astro build` 和 `astro db push` 时,都需要在本地设置环境变量。 libSQL 连接的详细信息(例如加密密钥、备份、同步间隔)可以配置为远程连接 URL 中的查询参数。 From 359ce36e9c68244cad529fc178cebd187a539237 Mon Sep 17 00:00:00 2001 From: Nin3 <30520689+Nin3lee@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:00:35 +0800 Subject: [PATCH 6/7] Update src/content/docs/zh-cn/guides/astro-db.mdx Co-authored-by: liruifengv --- src/content/docs/zh-cn/guides/astro-db.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content/docs/zh-cn/guides/astro-db.mdx b/src/content/docs/zh-cn/guides/astro-db.mdx index 63dd4cc0a754b..d16d003d44515 100644 --- a/src/content/docs/zh-cn/guides/astro-db.mdx +++ b/src/content/docs/zh-cn/guides/astro-db.mdx @@ -681,7 +681,6 @@ libSQL 同时支持 HTTP 和 WebSockets 作为远程服务器的传输协议。 - `memory:` 将使用内存数据库。在这种情况下,host 必须为空。 - `file:` 将使用本地文件。host 是文件的路径(`file:path/to/file.db`)。 -- `libsql:` will use a remote server through the protocol preferred by the library (this might be different across versions). The host is the address of the server (`libsql://your.server.io`). - `libsql:` 将通过库首选的协议使用远程服务器(可能因版本而异)。host 是服务器的地址(`libsql://your.server.io`)。 - `http:` 将通过 HTTP 使用远程服务器。`https:` 可用于启用安全连接。host 和 `libsql` 相同。 - `ws:` 将通过 WebSockets 使用远程服务器。`wss:` 可用于启用安全连接。 host 和 `libsql` 相同。 From 5e2d7cb8f9938c7a0b1279a6985af0c3a10823e9 Mon Sep 17 00:00:00 2001 From: Nin3 <30520689+Nin3lee@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:03:32 +0800 Subject: [PATCH 7/7] fix: add language identifier --- src/content/docs/zh-cn/guides/astro-db.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/zh-cn/guides/astro-db.mdx b/src/content/docs/zh-cn/guides/astro-db.mdx index d16d003d44515..bf08d9d5ec5d5 100644 --- a/src/content/docs/zh-cn/guides/astro-db.mdx +++ b/src/content/docs/zh-cn/guides/astro-db.mdx @@ -164,7 +164,7 @@ export default async function() { ### Drizzle ORM -``` +```ts import { db } from 'astro:db'; ```