Skip to content

Commit

Permalink
update database api
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 13, 2024
1 parent d866fd2 commit 0ed6cf4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vitepress build ."
},
"devDependencies": {
"@cordisjs/vitepress": "^3.2.5",
"@cordisjs/vitepress": "^3.2.6",
"@intlify/unplugin-vue-i18n": "^1.5.0",
"@koishijs/components": "^1.5.8",
"@koishijs/core": "^4.16.7",
"@koishijs/core": "^4.17.0-alpha.0",
"@koishijs/dns": "^1.0.1",
"@koishijs/market": "^4.2.3",
"@koishijs/registry": "^7.0.1",
"@koishijs/market": "^4.2.5",
"@koishijs/registry": "^7.0.3",
"@types/node": "^20.10.2",
"@types/spark-md5": "^3.0.4",
"@vueuse/core": "^10.6.1",
"cross-env": "^7.0.3",
"element-plus": "2.4.0",
"esbuild-register": "^3.5.0",
"koishi": "^4.16.7",
"koishi": "^4.17.0-alpha.0",
"markdown-it-mathjax3": "^4.3.2",
"marked-vue": "^1.3.0",
"typescript": "^5.3.2",
Expand Down
2 changes: 1 addition & 1 deletion zh-CN/api/core/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Koishi 使用了组合 (Compose) 的开发方式,绝大部分上下文属性
- **content:** `string` 要发送的内容
- 返回值: `Promise<string[]>` 成功发送的消息 ID 列表

所有机器人向自己分配的频道广播消息,存在标记 silent 的频道除外。如有失败不会抛出错误
所有机器人向自己分配的频道广播消息。如果传入的频道不存在,会输出一个警告

### ctx.logger(scope?)

Expand Down
22 changes: 19 additions & 3 deletions zh-CN/api/database/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,31 @@ export interface WriteResult {

计算聚合表达式。

### ctx.database.stats() <badge type="warning">实验性</badge>

- 返回值: [`Promise<Stats>`](#stats)

获取统计信息。

### ctx.database.drop(table)

- **table:** `string` 表名
- 返回值: `Promise<void>`

删除表。

### ctx.database.stats() <badge type="warning">实验性</badge>
::: danger
这是一个危险操作,删除表后将无法恢复数据。

- 返回值: [`Promise<Stats>`](#stats)
如果你是插件开发者,并希望重构插件的数据库结构,我们建议使用 [整表迁移](../../guide/database/model.md#整表迁移),以防止用户数据丢失。
:::

获取统计信息。
### ctx.database.dropAll()

- 返回值: `Promise<void>`

删除所有表。

::: danger
这是一个危险操作,删除表后将无法恢复数据。
:::
14 changes: 7 additions & 7 deletions zh-CN/guide/adapter/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ adapter-telegram
class ServerAdapter<C extends Context> extends Adapter<C, TelegramBot<C>> {}

namespace ServerAdapter {
export interface Config {
export interface Options {
protocol: 'server'
path?: string
}

export const Config: Schema<Config> = Schema.object({
export const Options: Schema<Options> = Schema.object({
protocol: Schema.const('server').required(),
path: Schema.string().default('/telegram'),
})
Expand All @@ -202,12 +202,12 @@ class PollingAdapter<C extends Context> extends Adapter<C, TelegramBot<C>> {
}

namespace PollingAdapter {
export interface Config {
export interface Options {
protocol: 'polling'
timeout?: string
}

export const Config: Schema<Config> = Schema.object({
export const Options: Schema<Options> = Schema.object({
protocol: Schema.const('server').required(),
timeout: Schema.number().default(Time.second * 25),
})
Expand All @@ -229,15 +229,15 @@ class TelegramBot<C extends Context> extends Bot<C, TelegramBot.Config> {
}

namespace TelegramBot {
export type Config = ServerAdapter.Config | PollingAdapter.Config
export type Config = ServerAdapter.Options | PollingAdapter.Options

export const Config: Schema<Config> = Schema.intersect([
Schema.object({
protocol: Schema.union(['server', 'polling']).required(),
}),
Schema.union([
HttpServer.Config,
HttpPolling.Config,
HttpServer.Options,
HttpPolling.Options,
]),
])
}
Expand Down

0 comments on commit 0ed6cf4

Please sign in to comment.