Skip to content

Commit

Permalink
0.1.30 fixes route errors and introduces deleteMany
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamint08 committed May 26, 2024
1 parent a3c22cd commit de46bad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/instances/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ class Mongo {
return collection.deleteOne(query);
}

async deleteMany(db: string, col: string, query: any): Promise<any> {
if (!this.isConnected) {
throw new Error('Not connected to MongoDB');
}
const collection = await this.getCollection(db, col);
return collection.deleteMany(query);
}

async close(): Promise<void> {
await this.client!.close();
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function loadFolder(folder: string) {
const allRoutes = new Glob(`${folder}/*.ts`);
for await (let file of allRoutes.scan(".")) {
file = file.replace(/\\/g, "/");
let realfile = file.replace(globalFolder + "/", "").replace(/.ts/g, "");
let realfile = file.replace(globalFolder + "/", "").replace(".ts", "");
file = file.split("/")[file.split("/").length - 1];
const splits = file.split("/");
const filePath = path.join(process.cwd(), folder, file);
Expand Down Expand Up @@ -233,6 +233,13 @@ async function handleRequest(req: Request): Promise<Response> {

async function startServer(port: number = 3000, routes: string = "routes", logger: boolean = true) {
await loadRoutes(routes);
// log routes
console.log(chalk.bold.white(`Routes:`));
for (const method in methods) {
for (const route in methods[method]) {
console.log(chalk.bold.white(` ${method.toUpperCase()} ${chalk.bold.green(route)}`));
}
}
console.log(chalk.bold.white(`Using ProBun ${chalk.bold.green(`v${version}`)}`));
console.log(chalk.bold.white(`Starting server on port ${chalk.bold.cyan(`${port}...`)}`));
Bun.serve({
Expand Down

0 comments on commit de46bad

Please sign in to comment.