Skip to content

Commit 82f1f4e

Browse files
authored
feat: add pyseekdb CLI entry point in pyproject.toml (#161)
Introduce a **CLI for pyseekdb** to support debugging and managing SeekDB databases/collections (close #55). ### Changes - **CLI 模块** - 新增 `src/pyseekdb/cli/__init__.py`、`src/pyseekdb/cli/main.py`,实现命令行入口与子命令分发。 - **连接方式**(与 spec 一致) - 嵌入式:`--path`(默认当前目录下 `seekdb.db`)。 - 服务端:`--host`、`--port`(默认 2881)、`--tenant`、`--database`、`--user`、`--password`(或环境变量 `SEEKDB_PASSWORD`)。 - **子命令** - **db**:`list` / `create <name>` / `delete <name>`(数据库管理)。 - **collections**(别名 **coll**):`list` / `create <name> [--dimension N]` / `delete <name>` / `info <name> [--sample N]`(collection 管理及预览)。 - **sql**:执行原始 SQL(调试用)。 - **query**:按文本对指定 collection 做向量/语义查询(`--text`、`--n`)。 - **get**:按 id 或 limit 拉取 collection 文档(`--ids`、`--limit`)。 - **输出**:全局 `-o table`(默认)或 `-o json`。 - **入口**:在 `pyproject.toml` 中增加 `[project.scripts]`,将 `pyseekdb` 指向 `pyseekdb.cli:main`。 ## Solution Description 针对 [issue #55](https://github.com/oceanbase/pyseekdb/issues/55),基于现有 `Client` / `AdminClient` 和 spec 中的连接与能力说明,实现一个统一的 CLI,便于: - **管理**:列出/创建/删除数据库与 collections,查看 collection 信息与样本数据。 - **调试**:执行任意 SQL、对 collection 做 query/get,支持 table 与 json 两种输出。 CLI 复用 `Client()` 与 `AdminClient()` 的工厂逻辑,支持嵌入式(`--path`)与服务端(`--host`/`--port` 等)两种模式;子命令通过 argparse 组织,无额外依赖。 ## Test plan - 安装后执行 `pyseekdb --help`、`pyseekdb db --help`、`pyseekdb collections --help` 等,确认子命令与参数展示正确。 - 在嵌入式或服务端环境下分别验证:`db list`、`collections list`、`collections info <name> --sample N`、`sql "SHOW TABLES"`、`query <collection> --text "..."`、`get <collection> --limit N` 及 `-o json` 输出,确认无报错且结果符合预期。 related to #55 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Packs a command-line interface (CLI) as a public executable entry point. * Adds DB management commands: list, create, delete. * Adds collection commands: list, create, delete, info (with optional sample). * Adds query, document retrieval, and raw SQL execution commands. * Supports embedded/server connection modes, configurable credentials, and output formats (table or JSON). <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent dc87918 commit 82f1f4e

3 files changed

Lines changed: 417 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ ignore = [
100100
[tool.ruff.format]
101101
preview = true
102102

103+
[project.scripts]
104+
pyseekdb = "pyseekdb.cli:main"
105+
103106
[build-system]
104107
requires = ["pdm-backend"]
105108
build-backend = "pdm.backend"

src/pyseekdb/cli/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
pyseekdb CLI - Debug and manage seekdb collections/databases.
3+
4+
Usage:
5+
pyseekdb [OPTIONS] db list|create|delete ...
6+
pyseekdb [OPTIONS] collections list|create|delete|info ...
7+
pyseekdb [OPTIONS] sql "SELECT ..."
8+
pyseekdb [OPTIONS] query <collection> --text "..." [--n 5]
9+
pyseekdb [OPTIONS] get <collection> [--limit 10] [--ids id1,id2]
10+
"""
11+
12+
from .main import main
13+
14+
__all__ = ["main"]

0 commit comments

Comments
 (0)