Skip to content

Commit 2169b26

Browse files
authored
Merge pull request #71 from mtichavsky/sqlite-fix
Fix sqlite3 bindings and revert sqlite support
2 parents 83cfb7c + 825c124 commit 2169b26

33 files changed

+15362
-96
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Connection String (preferred method)
44
# Use one of these DSN formats:
55
# DSN=postgres://user:password@localhost:5432/dbname
6+
# DSN=sqlite:///path/to/database.db
7+
# DSN=sqlite::memory:
68
# DSN=sqlserver://user:password@localhost:1433/dbname
79
# DSN=mysql://user:password@localhost:3306/dbname
810
DSN=

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Register connector with `ConnectorRegistry.register(connector)`
2424
- DSN Examples:
2525
- PostgreSQL: `postgres://user:password@localhost:5432/dbname`
26+
- SQLite: `sqlite:///path/to/database.db`
2627

2728
## Code Style
2829

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ COPY --from=builder /app/package.json /app/pnpm-lock.yaml ./
2828
# Install pnpm
2929
RUN corepack enable && corepack prepare pnpm@latest --activate
3030

31+
RUN pnpm pkg set pnpm.onlyBuiltDependencies[0]=better-sqlite3
32+
RUN pnpm add better-sqlite3
33+
RUN node -e 'new require("better-sqlite3")(":memory:")'
34+
3135
# Install production dependencies only
3236
RUN pnpm install --prod
3337

@@ -41,4 +45,4 @@ EXPOSE 8080
4145
ENV NODE_ENV=production
4246

4347
# Run the server
44-
ENTRYPOINT ["node", "dist/index.js"]
48+
ENTRYPOINT ["node", "dist/index.js"]

README.md

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ DBHub is a universal database gateway implementing the Model Context Protocol (M
2424
| | | | | |
2525
| Cursor +--->+ DBHub +--->+ SQL Server |
2626
| | | | | |
27+
| Other Clients +--->+ +--->+ SQLite |
28+
| | | | | |
2729
| | | +--->+ MySQL |
2830
| | | | | |
2931
| | | +--->+ MariaDB |
@@ -42,27 +44,27 @@ https://demo.dbhub.ai/message connects a [sample employee database](https://gith
4244

4345
### Database Resources
4446

45-
| Resource Name | URI Format | PostgreSQL | MySQL | MariaDB | SQL Server |
46-
| --------------------------- | ------------------------------------------------------ | :--------: | :---: | :-----: | :--------: |
47-
| schemas | `db://schemas` |||||
48-
| tables_in_schema | `db://schemas/{schemaName}/tables` |||||
49-
| table_structure_in_schema | `db://schemas/{schemaName}/tables/{tableName}` |||||
50-
| indexes_in_table | `db://schemas/{schemaName}/tables/{tableName}/indexes` |||||
51-
| procedures_in_schema | `db://schemas/{schemaName}/procedures` |||||
52-
| procedure_details_in_schema | `db://schemas/{schemaName}/procedures/{procedureName}` |||||
47+
| Resource Name | URI Format | PostgreSQL | MySQL | MariaDB | SQL Server | SQLite |
48+
| --------------------------- | ------------------------------------------------------ | :--------: | :---: | :-----: | :--------: | :----: |
49+
| schemas | `db://schemas` ||||||
50+
| tables_in_schema | `db://schemas/{schemaName}/tables` ||||||
51+
| table_structure_in_schema | `db://schemas/{schemaName}/tables/{tableName}` ||||||
52+
| indexes_in_table | `db://schemas/{schemaName}/tables/{tableName}/indexes` ||||||
53+
| procedures_in_schema | `db://schemas/{schemaName}/procedures` ||||||
54+
| procedure_details_in_schema | `db://schemas/{schemaName}/procedures/{procedureName}` ||||||
5355

5456
### Database Tools
5557

56-
| Tool | Command Name | Description | PostgreSQL | MySQL | MariaDB | SQL Server |
57-
| ----------- | ------------- | ------------------------------------------------------------------- | :--------: | :---: | :-----: | :--------: |
58-
| Execute SQL | `execute_sql` | Execute single or multiple SQL statements (separated by semicolons) |||||
58+
| Tool | Command Name | Description | PostgreSQL | MySQL | MariaDB | SQL Server | SQLite |
59+
| ----------- | ------------- | ------------------------------------------------------------------- | :--------: | :---: | :-----: | :--------: | ------ |
60+
| Execute SQL | `execute_sql` | Execute single or multiple SQL statements (separated by semicolons) ||||||
5961

6062
### Prompt Capabilities
6163

62-
| Prompt | Command Name | PostgreSQL | MySQL | MariaDB | SQL Server |
63-
| ------------------- | -------------- | :--------: | :---: | :-----: | :--------: |
64-
| Generate SQL | `generate_sql` |||||
65-
| Explain DB Elements | `explain_db` |||||
64+
| Prompt | Command Name | PostgreSQL | MySQL | MariaDB | SQL Server | SQLite |
65+
| ------------------- | -------------- | :--------: | :---: | :-----: | :--------: | ------ |
66+
| Generate SQL | `generate_sql` ||||||
67+
| Explain DB Elements | `explain_db` ||||||
6668

6769
## Installation
6870

@@ -79,6 +81,16 @@ docker run --rm --init \
7981
--dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
8082
```
8183

84+
```bash
85+
# Demo mode with sample employee database
86+
docker run --rm --init \
87+
--name dbhub \
88+
--publish 8080:8080 \
89+
bytebase/dbhub \
90+
--transport http \
91+
--port 8080 \
92+
--demo
93+
```
8294

8395

8496
### NPM
@@ -88,6 +100,12 @@ docker run --rm --init \
88100
npx @bytebase/dbhub --transport http --port 8080 --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
89101
```
90102

103+
```bash
104+
# Demo mode with sample employee database
105+
npx @bytebase/dbhub --transport http --port 8080 --demo
106+
```
107+
108+
> Note: The demo mode includes a bundled SQLite sample "employee" database with tables for employees, departments, salaries, and more.
91109
92110
### Claude Desktop
93111

@@ -124,6 +142,10 @@ npx @bytebase/dbhub --transport http --port 8080 --dsn "postgres://user:password
124142
"postgres://user:password@localhost:5432/dbname?sslmode=disable"
125143
]
126144
},
145+
"dbhub-demo": {
146+
"command": "npx",
147+
"args": ["-y", "@bytebase/dbhub", "--transport", "stdio", "--demo"]
148+
}
127149
}
128150
}
129151
```
@@ -149,6 +171,7 @@ You can specify the SSL mode using the `sslmode` parameter in your DSN string:
149171
| MySQL ||| Certificate verification |
150172
| MariaDB ||| Certificate verification |
151173
| SQL Server ||| Certificate verification |
174+
| SQLite ||| N/A (file-based) |
152175

153176
**SSL Mode Options:**
154177

@@ -185,6 +208,12 @@ This provides an additional layer of security when connecting to production data
185208

186209
### Configure your database connection
187210

211+
You can use DBHub in demo mode with a sample employee database for testing:
212+
213+
```bash
214+
npx @bytebase/dbhub --demo
215+
```
216+
188217
> [!WARNING]
189218
> If your user/password contains special characters, you need to escape them first. (e.g. `pass#word` should be escaped as `pass%23word`)
190219
@@ -221,6 +250,7 @@ DBHub supports the following database connection string formats:
221250
| MariaDB | `mariadb://[user]:[password]@[host]:[port]/[database]` | `mariadb://user:password@localhost:3306/dbname?sslmode=disable` |
222251
| PostgreSQL | `postgres://[user]:[password]@[host]:[port]/[database]` | `postgres://user:password@localhost:5432/dbname?sslmode=disable` |
223252
| SQL Server | `sqlserver://[user]:[password]@[host]:[port]/[database]` | `sqlserver://user:password@localhost:1433/dbname?sslmode=disable` |
253+
| SQLite | `sqlite:///[path/to/file]` or `sqlite:///:memory:` | `sqlite:///path/to/database.db`, `sqlite:C:/Users/YourName/data/database.db (windows)` or `sqlite:///:memory:` |
224254

225255

226256
#### SQL Server
@@ -246,13 +276,15 @@ Extra query parameters:
246276

247277
### Command line options
248278

249-
| Option | Environment Variable | Description | Default |
250-
| --------- | -------------------- | ---------------------------------------------------------------- | -------- |
251-
| dsn | `DSN` | Database connection string | Required |
252-
| transport | `TRANSPORT` | Transport mode: `stdio` or `http` | `stdio` |
253-
| port | `PORT` | HTTP server port (only applicable when using `--transport=http`) | `8080` |
254-
| readonly | `READONLY` | Restrict SQL execution to read-only operations | `false` |
279+
| Option | Environment Variable | Description | Default |
280+
| --------- | -------------------- | ---------------------------------------------------------------- | ---------------------------- |
281+
| dsn | `DSN` | Database connection string | Required if not in demo mode |
282+
| transport | `TRANSPORT` | Transport mode: `stdio` or `http` | `stdio` |
283+
| port | `PORT` | HTTP server port (only applicable when using `--transport=http`) | `8080` |
284+
| readonly | `READONLY` | Restrict SQL execution to read-only operations | `false` |
285+
| demo | N/A | Run in demo mode with sample employee database | `false` |
255286

287+
The demo mode uses an in-memory SQLite database loaded with the [sample employee database](https://github.com/bytebase/dbhub/tree/main/resources/employee-sqlite) that includes tables for employees, departments, titles, salaries, department employees, and department managers. The sample database includes SQL scripts for table creation, data loading, and testing.
256288

257289
## Development
258290

@@ -310,6 +342,8 @@ pnpm test src/connectors/__tests__/mysql.integration.test.ts
310342
pnpm test src/connectors/__tests__/mariadb.integration.test.ts
311343
# Run only SQL Server integration tests
312344
pnpm test src/connectors/__tests__/sqlserver.integration.test.ts
345+
# Run only SQLite integration tests
346+
pnpm test src/connectors/__tests__/sqlite.integration.test.ts
313347
# Run JSON RPC integration tests
314348
pnpm test src/__tests__/json-rpc-integration.test.ts
315349
```

0 commit comments

Comments
 (0)