Download src/lib/server/database.ts from MasterDee/chat-ui: direct link, hf CLI and curl.
- Browser
- Download file 832 Bytes
-
https://huggingface.co/spaces/MasterDee/chat-ui/resolve/833fd871fe5bdafa7e2e437e2dda0b638d3cdc19/src/lib/server/database.ts
- Command line
-
hf download hf://spaces/MasterDee/chat-ui@833fd871fe5bdafa7e2e437e2dda0b638d3cdc19/src/lib/server/database.ts
-
curl -L -o database.ts https://huggingface.co/spaces/MasterDee/chat-ui/resolve/833fd871fe5bdafa7e2e437e2dda0b638d3cdc19/src/lib/server/database.ts
832 Bytes
| import { MONGODB_URL, MONGODB_DB_NAME } from "$env/static/private"; | |
| import { MongoClient } from "mongodb"; | |
| import type { Conversation } from "$lib/types/Conversation"; | |
| import type { SharedConversation } from "$lib/types/SharedConversation"; | |
| const client = new MongoClient(MONGODB_URL, { | |
| // directConnection: true | |
| }); | |
| export const connectPromise = client.connect().catch(console.error); | |
| const db = client.db(MONGODB_DB_NAME); | |
| const conversations = db.collection<Conversation>("conversations"); | |
| const sharedConversations = db.collection<SharedConversation>("sharedConversations"); | |
| export { client, db }; | |
| export const collections = { conversations, sharedConversations }; | |
| client.on("open", () => { | |
| conversations.createIndex({ sessionId: 1, updatedAt: -1 }); | |
| sharedConversations.createIndex({ hash: 1 }, { unique: true }); | |
| }); | |