This commit is contained in:
Boki 2025-06-25 11:38:23 -04:00
parent 3a7254708e
commit b63e58784c
41 changed files with 5762 additions and 4477 deletions

View file

@ -16,7 +16,7 @@ export class SimpleMongoDBClient {
}
async find(collection: string, filter: any = {}): Promise<any[]> {
if (!this.connected) await this.connect();
if (!this.connected) {await this.connect();}
const docs = this.collections.get(collection) || [];
// Simple filter matching
@ -26,7 +26,7 @@ export class SimpleMongoDBClient {
return docs.filter(doc => {
for (const [key, value] of Object.entries(filter)) {
if (doc[key] !== value) return false;
if (doc[key] !== value) {return false;}
}
return true;
});
@ -38,7 +38,7 @@ export class SimpleMongoDBClient {
}
async insert(collection: string, doc: any): Promise<void> {
if (!this.connected) await this.connect();
if (!this.connected) {await this.connect();}
const docs = this.collections.get(collection) || [];
docs.push({ ...doc, _id: Math.random().toString(36) });
this.collections.set(collection, docs);
@ -51,10 +51,10 @@ export class SimpleMongoDBClient {
}
async update(collection: string, filter: any, update: any): Promise<number> {
if (!this.connected) await this.connect();
if (!this.connected) {await this.connect();}
const docs = await this.find(collection, filter);
if (docs.length === 0) return 0;
if (docs.length === 0) {return 0;}
const doc = docs[0];
if (update.$set) {
@ -65,7 +65,7 @@ export class SimpleMongoDBClient {
}
async updateMany(collection: string, filter: any, update: any): Promise<number> {
if (!this.connected) await this.connect();
if (!this.connected) {await this.connect();}
const docs = await this.find(collection, filter);
for (const doc of docs) {
@ -78,11 +78,11 @@ export class SimpleMongoDBClient {
}
async delete(collection: string, filter: any): Promise<number> {
if (!this.connected) await this.connect();
if (!this.connected) {await this.connect();}
const allDocs = this.collections.get(collection) || [];
const toDelete = await this.find(collection, filter);
if (toDelete.length === 0) return 0;
if (toDelete.length === 0) {return 0;}
const remaining = allDocs.filter(doc => !toDelete.includes(doc));
this.collections.set(collection, remaining);
@ -91,7 +91,7 @@ export class SimpleMongoDBClient {
}
async deleteMany(collection: string, filter: any): Promise<number> {
if (!this.connected) await this.connect();
if (!this.connected) {await this.connect();}
const allDocs = this.collections.get(collection) || [];
const toDelete = await this.find(collection, filter);
@ -102,7 +102,7 @@ export class SimpleMongoDBClient {
}
async batchUpsert(collection: string, documents: any[], uniqueKeys: string[]): Promise<void> {
if (!this.connected) await this.connect();
if (!this.connected) {await this.connect();}
for (const doc of documents) {
const filter: any = {};

View file

@ -22,18 +22,18 @@ export class SimplePostgresClient {
break;
}
}
if (match) return row;
if (match) {return row;}
}
return null;
}
async find(table: string, where: any): Promise<any[]> {
const rows = this.tables.get(table) || [];
if (Object.keys(where).length === 0) return rows;
if (Object.keys(where).length === 0) {return rows;}
return rows.filter(row => {
for (const [key, value] of Object.entries(where)) {
if (row[key] !== value) return false;
if (row[key] !== value) {return false;}
}
return true;
});
@ -72,7 +72,7 @@ export class SimplePostgresClient {
const rows = this.tables.get(table) || [];
const remaining = rows.filter(row => {
for (const [key, value] of Object.entries(where)) {
if (row[key] !== value) return true;
if (row[key] !== value) {return true;}
}
return false;
});

File diff suppressed because it is too large Load diff