fixed format issues

This commit is contained in:
Boki 2025-06-26 16:12:27 -04:00
parent a700818a06
commit 08f713d98b
55 changed files with 5680 additions and 5533 deletions

View file

@ -16,7 +16,9 @@ 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 +28,9 @@ 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 +42,9 @@ 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 +57,14 @@ 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 +75,9 @@ 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 +90,15 @@ 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 +107,9 @@ 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 +120,9 @@ 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,24 @@ 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 +78,9 @@ 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;
});