Add features

This commit is contained in:
2024-09-12 14:37:08 +00:00
parent f5948621f0
commit a89150fc2f
22 changed files with 1145 additions and 99 deletions

37
src/utils/db/game.js Normal file
View File

@@ -0,0 +1,37 @@
import { MongoClient } from 'mongodb';
if (!process.env.MONGODB_URI) {
throw new Error('MONGODB_URI is not set in the environment variables.');
}
const client = new MongoClient(process.env.MONGODB_URI);
await client.connect();
const database = client.db('butler_db');
const collection = database.collection('GameFeatures');
export async function listGameNames() {
return collection.find({}, { projection: { game: 1 } }).toArray();
}
export async function getGame(game) {
return collection.findOne({ game });
}
export async function setGame(game, key, value) {
// If game is not found, create a new document with game field set to game, and key field set to value.
// Overwrite the value of the key field if it already exists.
return collection.updateOne(
{ game },
{ $set: { game, [key]: value } },
{ upsert: true }
);
}
export async function deleteGame(game) {
return collection.deleteOne({ game });
}
export async function deleteField(game, key) {
return collection.updateOne({ game }, { $unset: { [key]: '' } });
}