Skip to content

Commit 05bf5b9

Browse files
committed
docs(readme): add brief DB adapters section; feat(db): add portable DB port + browser/server adapters
1 parent e80ba6e commit 05bf5b9

File tree

8 files changed

+574
-4
lines changed

8 files changed

+574
-4
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ SECRET_CONFIG
1212
!.env.ci
1313
!.env
1414
gcp-*.json
15-
db
15+
# Only ignore the top-level database folder used by local Mongo storage
16+
/db
17+
packages/**/db
1618
models/*
17-
!models/add-your-models-here.txt
19+
!models/add-your-models-here.txt

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ In which case the url of your DB will be `MONGODB_URL=mongodb://localhost:27017`
114114

115115
Alternatively, you can use a [free MongoDB Atlas](https://www.mongodb.com/pricing) instance for this, Chat UI should fit comfortably within their free tier. After which you can set the `MONGODB_URL` variable in `.env.local` to match your instance.
116116

117+
### DB adapters (Mongo server + IndexedDB browser)
118+
119+
This branch exposes a small, storage‑agnostic DB “port” under `src/lib/db` so the same API can run on the server (MongoDB) or in the browser (IndexedDB via Dexie):
120+
121+
- Server: existing centralized Mongo service at `$lib/server/db` (no change for server routes).
122+
- Browser: `import { getDB } from "$lib/db"; const db = await getDB();` exposes the same methods (e.g. `db.conversations.insert`, `db.shared.findByHash`).
123+
124+
Example (browser or server):
125+
126+
```ts
127+
import { getDB } from "$lib/db";
128+
129+
const db = await getDB();
130+
await db.conversations.updateFields(id, { title: "New title" });
131+
```
132+
133+
Notes:
134+
- `openUploadStream` is server‑only; in the browser use existing HTTP upload routes.
135+
- Browser adapter stores IDs as strings; avoid relying on `instanceof ObjectId` in client code.
136+
117137
### Hugging Face Access Token
118138

119139
If you use the Hugging Face router, you will need a Hugging Face access token to run Chat UI locally. You can get one from [your Hugging Face profile](https://huggingface.co/settings/tokens).

package-lock.json

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@resvg/resvg-js": "^2.6.2",
7575
"autoprefixer": "^10.4.14",
7676
"date-fns": "^2.29.3",
77+
"dexie": "^4.0.8",
7778
"dotenv": "^16.5.0",
7879
"file-type": "^21.0.0",
7980
"handlebars": "^4.7.8",

0 commit comments

Comments
 (0)