@black-cyq/sql-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/bin/sql-cli.js +61 -0
- package/jar/sql-cli.jar +0 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cyq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# SQL-CLI
|
|
2
|
+
|
|
3
|
+
[](https://openjdk.org/projects/jdk/21/)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/xianyuchen-king/sql-cli/releases)
|
|
6
|
+
[](https://www.npmjs.com/package/@black-cyq/sql-cli)
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
一个用于连接关系型数据库的 CLI 工具,通过 JDBC 驱动支持 MySQL、Oracle、PostgreSQL、SQLite、达梦等数据库。专为 AI 编程助手(如 Claude Code)设计。
|
|
10
|
+
|
|
11
|
+
> **Beta 测试阶段** — 本项目正在积极开发中,欢迎试用并[提出反馈](https://github.com/xianyuchen-king/sql-cli/issues/new?template=bug_report.yml)或[功能建议](https://github.com/xianyuchen-king/sql-cli/issues/new?template=feature_request.yml)!
|
|
12
|
+
|
|
13
|
+
[English](README_EN.md) | 中文
|
|
14
|
+
|
|
15
|
+
## 特性
|
|
16
|
+
|
|
17
|
+
- **多数据库支持** — MySQL、Oracle、PostgreSQL、SQLite、达梦等,可通过自定义驱动扩展
|
|
18
|
+
- **安全保护** — 密码 AES-256-GCM 加密存储、安全级别控制(严格/正常/无)
|
|
19
|
+
- **数据导入导出** — CSV、JSON、SQL INSERT/UPDATE 格式
|
|
20
|
+
- **连接管理** — 保存连接配置,支持分组和标签
|
|
21
|
+
- **元数据浏览** — 查看数据库、表、列、索引信息
|
|
22
|
+
- **AI 友好** — 默认 Markdown 表格输出,专为 AI 助手优化
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
### 前置要求
|
|
27
|
+
|
|
28
|
+
- Java 21+ 已安装并在 PATH 中
|
|
29
|
+
- Node.js 16+(仅 npm 安装方式需要)
|
|
30
|
+
|
|
31
|
+
### 方式一:npm 安装(推荐)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install -g @black-cyq/sql-cli
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
安装完成后即可使用 `sql-cli` 命令。
|
|
38
|
+
|
|
39
|
+
### 方式二:从源码构建
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/xianyuchen-king/sql-cli.git
|
|
43
|
+
cd sql-cli
|
|
44
|
+
./gradlew shadowJar
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
构建完成后,jar 文件位于 `build/libs/sql-cli.jar`。
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# 直接运行
|
|
51
|
+
java -jar build/libs/sql-cli.jar --help
|
|
52
|
+
|
|
53
|
+
# 或创建启动脚本
|
|
54
|
+
sudo tee /usr/local/bin/sql-cli << 'EOF'
|
|
55
|
+
#!/bin/bash
|
|
56
|
+
java -jar /path/to/sql-cli/build/libs/sql-cli.jar "$@"
|
|
57
|
+
EOF
|
|
58
|
+
sudo chmod +x /usr/local/bin/sql-cli
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 方式三:下载预编译版本
|
|
62
|
+
|
|
63
|
+
前往 [Releases](https://github.com/xianyuchen-king/sql-cli/releases) 页面下载最新 jar 文件。
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
java -jar sql-cli.jar --help
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 快速开始
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 1. 初始化配置
|
|
73
|
+
sql-cli init
|
|
74
|
+
|
|
75
|
+
# 2. 安装数据库驱动
|
|
76
|
+
sql-cli driver install mysql
|
|
77
|
+
|
|
78
|
+
# 3. 添加连接
|
|
79
|
+
sql-cli conn add --name mydb --type mysql --host localhost --port 3306 \
|
|
80
|
+
--user root --password xxx --db testdb
|
|
81
|
+
|
|
82
|
+
# 4. 测试连接
|
|
83
|
+
sql-cli conn test mydb -v
|
|
84
|
+
|
|
85
|
+
# 5. 执行查询
|
|
86
|
+
sql-cli query "SELECT * FROM users LIMIT 10" -c mydb
|
|
87
|
+
|
|
88
|
+
# 6. 导出数据
|
|
89
|
+
sql-cli export -t users -c mydb -f csv -o /tmp/users.csv
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 使用示例
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
$ sql-cli query "SELECT id, name, email FROM users LIMIT 5" -c mydb
|
|
96
|
+
|
|
97
|
+
| id | name | email |
|
|
98
|
+
|----|----------|--------------------|
|
|
99
|
+
| 1 | Alice | alice@example.com |
|
|
100
|
+
| 2 | Bob | bob@example.com |
|
|
101
|
+
| 3 | Charlie | charlie@example.com |
|
|
102
|
+
|
|
103
|
+
5 rows in set (0.03s)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
更多用法详见 [完整文档](skill/sql-cli-skill.md)。
|
|
107
|
+
|
|
108
|
+
## 支持的数据库
|
|
109
|
+
|
|
110
|
+
| 数据库 | 类型标识 | 默认端口 |
|
|
111
|
+
|-----------|---------------|---------|
|
|
112
|
+
| MySQL | `mysql` | 3306 |
|
|
113
|
+
| Oracle | `oracle` | 1521 |
|
|
114
|
+
| PostgreSQL| `postgresql` | 5432 |
|
|
115
|
+
| SQLite | `sqlite` | - |
|
|
116
|
+
| 达梦 | `dm`(自定义) | 5236 |
|
|
117
|
+
| 其他 | `generic` | - |
|
|
118
|
+
|
|
119
|
+
## 技术栈
|
|
120
|
+
|
|
121
|
+
- Java 21、Gradle、Picocli(CLI 框架)、SnakeYAML(YAML 处理)、JDBC
|
|
122
|
+
|
|
123
|
+
## 贡献
|
|
124
|
+
|
|
125
|
+
欢迎贡献代码、报告 Bug 或提出建议!请阅读 [贡献指南](CONTRIBUTING.md)。
|
|
126
|
+
|
|
127
|
+
## 反馈与建议
|
|
128
|
+
|
|
129
|
+
- [报告 Bug](https://github.com/xianyuchen-king/sql-cli/issues/new?template=bug_report.yml)
|
|
130
|
+
- [功能建议](https://github.com/xianyuchen-king/sql-cli/issues/new?template=feature_request.yml)
|
|
131
|
+
- [讨论区](https://github.com/xianyuchen-king/sql-cli/discussions)
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
[MIT](LICENSE)
|
package/bin/sql-cli.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const { existsSync } = require('fs');
|
|
6
|
+
const { join } = require('path');
|
|
7
|
+
const { execSync } = require('child_process');
|
|
8
|
+
const { platform } = require('os');
|
|
9
|
+
|
|
10
|
+
// Resolve jar path
|
|
11
|
+
const jarDir = join(__dirname, '..', 'jar');
|
|
12
|
+
const jarFile = join(jarDir, 'sql-cli.jar');
|
|
13
|
+
|
|
14
|
+
// Check Java installation
|
|
15
|
+
function checkJava() {
|
|
16
|
+
try {
|
|
17
|
+
const version = execSync('java -version 2>&1', { encoding: 'utf8' });
|
|
18
|
+
const match = version.match(/version "(\d+)/);
|
|
19
|
+
if (match && parseInt(match[1]) >= 17) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
console.error('Error: sql-cli requires Java 17 or later.');
|
|
23
|
+
console.error(`Found Java version: ${match ? match[1] : 'unknown'}`);
|
|
24
|
+
console.error('Please install Java 21+: https://adoptium.net/');
|
|
25
|
+
process.exit(1);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error('Error: Java is not installed or not on PATH.');
|
|
28
|
+
console.error('sql-cli requires Java 17 or later.');
|
|
29
|
+
console.error('Please install Java 21+: https://adoptium.net/');
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Check jar file
|
|
35
|
+
function checkJar() {
|
|
36
|
+
if (!existsSync(jarFile)) {
|
|
37
|
+
console.error(`Error: sql-cli.jar not found at ${jarFile}`);
|
|
38
|
+
if (existsSync(join(__dirname, '..', 'node_modules'))) {
|
|
39
|
+
console.error('Please reinstall: npm install -g @black-cyq/sql-cli');
|
|
40
|
+
} else {
|
|
41
|
+
console.error('Please build first: ./gradlew shadowJar && mkdir -p jar && cp build/libs/sql-cli.jar jar/');
|
|
42
|
+
}
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Main
|
|
48
|
+
checkJava();
|
|
49
|
+
checkJar();
|
|
50
|
+
|
|
51
|
+
const args = process.argv.slice(2);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
execSync(`java -jar "${jarFile}" ${args.map(a => `"${a}"`).join(' ')}`, {
|
|
55
|
+
stdio: 'inherit',
|
|
56
|
+
env: { ...process.env }
|
|
57
|
+
});
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Exit with the same code as the java process
|
|
60
|
+
process.exit(e.status || 1);
|
|
61
|
+
}
|
package/jar/sql-cli.jar
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@black-cyq/sql-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A CLI tool for connecting to relational databases (MySQL, Oracle, PostgreSQL, SQLite, etc.) via JDBC. Designed for AI coding agents like Claude Code.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"sql-cli": "./bin/sql-cli.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/sql-cli.js",
|
|
10
|
+
"jar/",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"prepack": "./scripts/build-jar.sh",
|
|
15
|
+
"postinstall": "node scripts/postinstall.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"sql",
|
|
19
|
+
"cli",
|
|
20
|
+
"database",
|
|
21
|
+
"mysql",
|
|
22
|
+
"oracle",
|
|
23
|
+
"postgresql",
|
|
24
|
+
"sqlite",
|
|
25
|
+
"jdbc",
|
|
26
|
+
"claude-code",
|
|
27
|
+
"ai-agent"
|
|
28
|
+
],
|
|
29
|
+
"author": "cyq",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=16"
|
|
33
|
+
}
|
|
34
|
+
}
|