@prisma-next/driver-mongo 0.3.0-dev.134 → 0.3.0-dev.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +33 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/src/mongo-driver.ts +72 -27
package/dist/index.d.mts
CHANGED
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"sourcesContent":[],"mappings":";;;iBAiIsB,iBAAA,+BAAgD,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -10,10 +10,14 @@ var MongoDriverImpl = class {
|
|
|
10
10
|
}
|
|
11
11
|
execute(wireCommand) {
|
|
12
12
|
switch (wireCommand.kind) {
|
|
13
|
-
case "find": return this.#executeFindCommand(wireCommand);
|
|
14
13
|
case "insertOne": return this.#executeInsertOneCommand(wireCommand);
|
|
15
14
|
case "updateOne": return this.#executeUpdateOneCommand(wireCommand);
|
|
15
|
+
case "insertMany": return this.#executeInsertManyCommand(wireCommand);
|
|
16
|
+
case "updateMany": return this.#executeUpdateManyCommand(wireCommand);
|
|
16
17
|
case "deleteOne": return this.#executeDeleteOneCommand(wireCommand);
|
|
18
|
+
case "deleteMany": return this.#executeDeleteManyCommand(wireCommand);
|
|
19
|
+
case "findOneAndUpdate": return this.#executeFindOneAndUpdateCommand(wireCommand);
|
|
20
|
+
case "findOneAndDelete": return this.#executeFindOneAndDeleteCommand(wireCommand);
|
|
17
21
|
case "aggregate": return this.#executeAggregateCommand(wireCommand);
|
|
18
22
|
default: {
|
|
19
23
|
const _exhaustive = wireCommand;
|
|
@@ -24,14 +28,6 @@ var MongoDriverImpl = class {
|
|
|
24
28
|
async close() {
|
|
25
29
|
await this.#client.close();
|
|
26
30
|
}
|
|
27
|
-
async *#executeFindCommand(cmd) {
|
|
28
|
-
let cursor = this.#db.collection(cmd.collection).find(cmd.filter ?? {});
|
|
29
|
-
if (cmd.projection) cursor = cursor.project(cmd.projection);
|
|
30
|
-
if (cmd.sort) cursor = cursor.sort(cmd.sort);
|
|
31
|
-
if (cmd.limit !== void 0) cursor = cursor.limit(cmd.limit);
|
|
32
|
-
if (cmd.skip !== void 0) cursor = cursor.skip(cmd.skip);
|
|
33
|
-
yield* cursor;
|
|
34
|
-
}
|
|
35
31
|
async *#executeInsertOneCommand(cmd) {
|
|
36
32
|
yield { insertedId: (await this.#db.collection(cmd.collection).insertOne(cmd.document)).insertedId };
|
|
37
33
|
}
|
|
@@ -42,9 +38,37 @@ var MongoDriverImpl = class {
|
|
|
42
38
|
modifiedCount: result.modifiedCount
|
|
43
39
|
};
|
|
44
40
|
}
|
|
41
|
+
async *#executeInsertManyCommand(cmd) {
|
|
42
|
+
const result = await this.#db.collection(cmd.collection).insertMany(cmd.documents);
|
|
43
|
+
yield {
|
|
44
|
+
insertedIds: Object.values(result.insertedIds),
|
|
45
|
+
insertedCount: result.insertedCount
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async *#executeUpdateManyCommand(cmd) {
|
|
49
|
+
const result = await this.#db.collection(cmd.collection).updateMany(cmd.filter, cmd.update);
|
|
50
|
+
yield {
|
|
51
|
+
matchedCount: result.matchedCount,
|
|
52
|
+
modifiedCount: result.modifiedCount
|
|
53
|
+
};
|
|
54
|
+
}
|
|
45
55
|
async *#executeDeleteOneCommand(cmd) {
|
|
46
56
|
yield { deletedCount: (await this.#db.collection(cmd.collection).deleteOne(cmd.filter)).deletedCount };
|
|
47
57
|
}
|
|
58
|
+
async *#executeDeleteManyCommand(cmd) {
|
|
59
|
+
yield { deletedCount: (await this.#db.collection(cmd.collection).deleteMany(cmd.filter)).deletedCount };
|
|
60
|
+
}
|
|
61
|
+
async *#executeFindOneAndUpdateCommand(cmd) {
|
|
62
|
+
const result = await this.#db.collection(cmd.collection).findOneAndUpdate(cmd.filter, cmd.update, {
|
|
63
|
+
returnDocument: "after",
|
|
64
|
+
upsert: cmd.upsert
|
|
65
|
+
});
|
|
66
|
+
if (result) yield result;
|
|
67
|
+
}
|
|
68
|
+
async *#executeFindOneAndDeleteCommand(cmd) {
|
|
69
|
+
const result = await this.#db.collection(cmd.collection).findOneAndDelete(cmd.filter);
|
|
70
|
+
if (result) yield result;
|
|
71
|
+
}
|
|
48
72
|
async *#executeAggregateCommand(cmd) {
|
|
49
73
|
yield* this.#db.collection(cmd.collection).aggregate(cmd.pipeline);
|
|
50
74
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#db","#client","#
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#db","#client","#executeInsertOneCommand","#executeUpdateOneCommand","#executeInsertManyCommand","#executeUpdateManyCommand","#executeDeleteOneCommand","#executeDeleteManyCommand","#executeFindOneAndUpdateCommand","#executeFindOneAndDeleteCommand","#executeAggregateCommand","_exhaustive: never"],"sources":["../src/mongo-driver.ts"],"sourcesContent":["import type { MongoDriver } from '@prisma-next/mongo-lowering';\nimport type {\n AggregateWireCommand,\n AnyMongoWireCommand,\n DeleteManyResult,\n DeleteManyWireCommand,\n DeleteOneResult,\n DeleteOneWireCommand,\n FindOneAndDeleteWireCommand,\n FindOneAndUpdateWireCommand,\n InsertManyResult,\n InsertManyWireCommand,\n InsertOneResult,\n InsertOneWireCommand,\n UpdateManyResult,\n UpdateManyWireCommand,\n UpdateOneResult,\n UpdateOneWireCommand,\n} from '@prisma-next/mongo-wire';\nimport { type Db, MongoClient } from 'mongodb';\n\nclass MongoDriverImpl implements MongoDriver {\n readonly #db: Db;\n readonly #client: MongoClient;\n\n constructor(db: Db, client: MongoClient) {\n this.#db = db;\n this.#client = client;\n }\n\n execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row> {\n switch (wireCommand.kind) {\n case 'insertOne':\n return this.#executeInsertOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'updateOne':\n return this.#executeUpdateOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'insertMany':\n return this.#executeInsertManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'updateMany':\n return this.#executeUpdateManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'deleteOne':\n return this.#executeDeleteOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'deleteMany':\n return this.#executeDeleteManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'findOneAndUpdate':\n return this.#executeFindOneAndUpdateCommand(wireCommand) as AsyncIterable<Row>;\n case 'findOneAndDelete':\n return this.#executeFindOneAndDeleteCommand(wireCommand) as AsyncIterable<Row>;\n case 'aggregate':\n return this.#executeAggregateCommand<Row>(wireCommand);\n // v8 ignore next 4\n default: {\n const _exhaustive: never = wireCommand;\n throw new Error(`Unknown wire command kind: ${(_exhaustive as { kind: string }).kind}`);\n }\n }\n }\n\n async close(): Promise<void> {\n await this.#client.close();\n }\n\n async *#executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.insertOne(cmd.document);\n yield { insertedId: result.insertedId };\n }\n\n async *#executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.updateOne(cmd.filter, cmd.update);\n yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };\n }\n\n async *#executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.insertMany(cmd.documents as Record<string, unknown>[]);\n const insertedIds = Object.values(result.insertedIds);\n yield { insertedIds, insertedCount: result.insertedCount };\n }\n\n async *#executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.updateMany(cmd.filter, cmd.update);\n yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };\n }\n\n async *#executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.deleteOne(cmd.filter);\n yield { deletedCount: result.deletedCount };\n }\n\n async *#executeDeleteManyCommand(cmd: DeleteManyWireCommand): AsyncIterable<DeleteManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.deleteMany(cmd.filter);\n yield { deletedCount: result.deletedCount };\n }\n\n async *#executeFindOneAndUpdateCommand(\n cmd: FindOneAndUpdateWireCommand,\n ): AsyncIterable<Record<string, unknown>> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.findOneAndUpdate(cmd.filter, cmd.update, {\n returnDocument: 'after',\n upsert: cmd.upsert,\n });\n if (result) {\n yield result as Record<string, unknown>;\n }\n }\n\n async *#executeFindOneAndDeleteCommand(\n cmd: FindOneAndDeleteWireCommand,\n ): AsyncIterable<Record<string, unknown>> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.findOneAndDelete(cmd.filter);\n if (result) {\n yield result as Record<string, unknown>;\n }\n }\n\n async *#executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row> {\n const collection = this.#db.collection(cmd.collection);\n const cursor = collection.aggregate(cmd.pipeline as Record<string, unknown>[]);\n yield* cursor as AsyncIterable<Row>;\n }\n}\n\nexport async function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver> {\n const client = new MongoClient(uri);\n await client.connect();\n const db = client.db(dbName);\n return new MongoDriverImpl(db, client);\n}\n"],"mappings":";;;AAqBA,IAAM,kBAAN,MAA6C;CAC3C,CAASA;CACT,CAASC;CAET,YAAY,IAAQ,QAAqB;AACvC,QAAKD,KAAM;AACX,QAAKC,SAAU;;CAGjB,QAAuC,aAAsD;AAC3F,UAAQ,YAAY,MAApB;GACE,KAAK,YACH,QAAO,MAAKC,wBAAyB,YAAY;GACnD,KAAK,YACH,QAAO,MAAKC,wBAAyB,YAAY;GACnD,KAAK,aACH,QAAO,MAAKC,yBAA0B,YAAY;GACpD,KAAK,aACH,QAAO,MAAKC,yBAA0B,YAAY;GACpD,KAAK,YACH,QAAO,MAAKC,wBAAyB,YAAY;GACnD,KAAK,aACH,QAAO,MAAKC,yBAA0B,YAAY;GACpD,KAAK,mBACH,QAAO,MAAKC,+BAAgC,YAAY;GAC1D,KAAK,mBACH,QAAO,MAAKC,+BAAgC,YAAY;GAC1D,KAAK,YACH,QAAO,MAAKC,wBAA8B,YAAY;GAExD,SAAS;IACP,MAAMC,cAAqB;AAC3B,UAAM,IAAI,MAAM,8BAA+B,YAAiC,OAAO;;;;CAK7F,MAAM,QAAuB;AAC3B,QAAM,MAAKV,OAAQ,OAAO;;CAG5B,QAAOC,wBAAyB,KAA2D;AAGzF,QAAM,EAAE,aADO,MADI,MAAKF,GAAI,WAAW,IAAI,WAAW,CACtB,UAAU,IAAI,SAAS,EAC5B,YAAY;;CAGzC,QAAOG,wBAAyB,KAA2D;EAEzF,MAAM,SAAS,MADI,MAAKH,GAAI,WAAW,IAAI,WAAW,CACtB,UAAU,IAAI,QAAQ,IAAI,OAAO;AACjE,QAAM;GAAE,cAAc,OAAO;GAAc,eAAe,OAAO;GAAe;;CAGlF,QAAOI,yBAA0B,KAA6D;EAE5F,MAAM,SAAS,MADI,MAAKJ,GAAI,WAAW,IAAI,WAAW,CACtB,WAAW,IAAI,UAAuC;AAEtF,QAAM;GAAE,aADY,OAAO,OAAO,OAAO,YAAY;GAChC,eAAe,OAAO;GAAe;;CAG5D,QAAOK,yBAA0B,KAA6D;EAE5F,MAAM,SAAS,MADI,MAAKL,GAAI,WAAW,IAAI,WAAW,CACtB,WAAW,IAAI,QAAQ,IAAI,OAAO;AAClE,QAAM;GAAE,cAAc,OAAO;GAAc,eAAe,OAAO;GAAe;;CAGlF,QAAOM,wBAAyB,KAA2D;AAGzF,QAAM,EAAE,eADO,MADI,MAAKN,GAAI,WAAW,IAAI,WAAW,CACtB,UAAU,IAAI,OAAO,EACxB,cAAc;;CAG7C,QAAOO,yBAA0B,KAA6D;AAG5F,QAAM,EAAE,eADO,MADI,MAAKP,GAAI,WAAW,IAAI,WAAW,CACtB,WAAW,IAAI,OAAO,EACzB,cAAc;;CAG7C,QAAOQ,+BACL,KACwC;EAExC,MAAM,SAAS,MADI,MAAKR,GAAI,WAAW,IAAI,WAAW,CACtB,iBAAiB,IAAI,QAAQ,IAAI,QAAQ;GACvE,gBAAgB;GAChB,QAAQ,IAAI;GACb,CAAC;AACF,MAAI,OACF,OAAM;;CAIV,QAAOS,+BACL,KACwC;EAExC,MAAM,SAAS,MADI,MAAKT,GAAI,WAAW,IAAI,WAAW,CACtB,iBAAiB,IAAI,OAAO;AAC5D,MAAI,OACF,OAAM;;CAIV,QAAOU,wBAA8B,KAA+C;AAGlF,SAFmB,MAAKV,GAAI,WAAW,IAAI,WAAW,CAC5B,UAAU,IAAI,SAAsC;;;AAKlF,eAAsB,kBAAkB,KAAa,QAAsC;CACzF,MAAM,SAAS,IAAI,YAAY,IAAI;AACnC,OAAM,OAAO,SAAS;AAEtB,QAAO,IAAI,gBADA,OAAO,GAAG,OAAO,EACG,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/driver-mongo",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.146",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "MongoDB driver for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"mongodb": "^6.16.0",
|
|
9
|
-
"@prisma-next/mongo-
|
|
9
|
+
"@prisma-next/mongo-lowering": "0.3.0-dev.146",
|
|
10
|
+
"@prisma-next/mongo-wire": "0.3.0-dev.146"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
13
|
"mongodb-memory-server": "^10.4.0",
|
|
@@ -14,8 +15,8 @@
|
|
|
14
15
|
"typescript": "5.9.3",
|
|
15
16
|
"vitest": "4.0.17",
|
|
16
17
|
"@prisma-next/test-utils": "0.0.1",
|
|
17
|
-
"@prisma-next/
|
|
18
|
-
"@prisma-next/
|
|
18
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
19
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
22
|
"dist",
|
package/src/mongo-driver.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
import type { MongoDriver } from '@prisma-next/mongo-lowering';
|
|
1
2
|
import type {
|
|
3
|
+
AggregateWireCommand,
|
|
2
4
|
AnyMongoWireCommand,
|
|
5
|
+
DeleteManyResult,
|
|
6
|
+
DeleteManyWireCommand,
|
|
3
7
|
DeleteOneResult,
|
|
8
|
+
DeleteOneWireCommand,
|
|
9
|
+
FindOneAndDeleteWireCommand,
|
|
10
|
+
FindOneAndUpdateWireCommand,
|
|
11
|
+
InsertManyResult,
|
|
12
|
+
InsertManyWireCommand,
|
|
4
13
|
InsertOneResult,
|
|
5
|
-
|
|
14
|
+
InsertOneWireCommand,
|
|
15
|
+
UpdateManyResult,
|
|
16
|
+
UpdateManyWireCommand,
|
|
6
17
|
UpdateOneResult,
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
UpdateOneWireCommand,
|
|
19
|
+
} from '@prisma-next/mongo-wire';
|
|
20
|
+
import { type Db, MongoClient } from 'mongodb';
|
|
9
21
|
|
|
10
22
|
class MongoDriverImpl implements MongoDriver {
|
|
11
23
|
readonly #db: Db;
|
|
@@ -18,16 +30,25 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
18
30
|
|
|
19
31
|
execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row> {
|
|
20
32
|
switch (wireCommand.kind) {
|
|
21
|
-
case 'find':
|
|
22
|
-
return this.#executeFindCommand<Row>(wireCommand);
|
|
23
33
|
case 'insertOne':
|
|
24
34
|
return this.#executeInsertOneCommand(wireCommand) as AsyncIterable<Row>;
|
|
25
35
|
case 'updateOne':
|
|
26
36
|
return this.#executeUpdateOneCommand(wireCommand) as AsyncIterable<Row>;
|
|
37
|
+
case 'insertMany':
|
|
38
|
+
return this.#executeInsertManyCommand(wireCommand) as AsyncIterable<Row>;
|
|
39
|
+
case 'updateMany':
|
|
40
|
+
return this.#executeUpdateManyCommand(wireCommand) as AsyncIterable<Row>;
|
|
27
41
|
case 'deleteOne':
|
|
28
42
|
return this.#executeDeleteOneCommand(wireCommand) as AsyncIterable<Row>;
|
|
43
|
+
case 'deleteMany':
|
|
44
|
+
return this.#executeDeleteManyCommand(wireCommand) as AsyncIterable<Row>;
|
|
45
|
+
case 'findOneAndUpdate':
|
|
46
|
+
return this.#executeFindOneAndUpdateCommand(wireCommand) as AsyncIterable<Row>;
|
|
47
|
+
case 'findOneAndDelete':
|
|
48
|
+
return this.#executeFindOneAndDeleteCommand(wireCommand) as AsyncIterable<Row>;
|
|
29
49
|
case 'aggregate':
|
|
30
50
|
return this.#executeAggregateCommand<Row>(wireCommand);
|
|
51
|
+
// v8 ignore next 4
|
|
31
52
|
default: {
|
|
32
53
|
const _exhaustive: never = wireCommand;
|
|
33
54
|
throw new Error(`Unknown wire command kind: ${(_exhaustive as { kind: string }).kind}`);
|
|
@@ -39,43 +60,67 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
39
60
|
await this.#client.close();
|
|
40
61
|
}
|
|
41
62
|
|
|
42
|
-
async *#
|
|
43
|
-
const collection = this.#db.collection(cmd.collection);
|
|
44
|
-
let cursor = collection.find(cmd.filter ?? {});
|
|
45
|
-
if (cmd.projection) cursor = cursor.project(cmd.projection);
|
|
46
|
-
if (cmd.sort) cursor = cursor.sort(cmd.sort as Sort);
|
|
47
|
-
if (cmd.limit !== undefined) cursor = cursor.limit(cmd.limit);
|
|
48
|
-
if (cmd.skip !== undefined) cursor = cursor.skip(cmd.skip);
|
|
49
|
-
yield* cursor as AsyncIterable<Row>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async *#executeInsertOneCommand(
|
|
53
|
-
cmd: AnyMongoWireCommand & { kind: 'insertOne' },
|
|
54
|
-
): AsyncIterable<InsertOneResult> {
|
|
63
|
+
async *#executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult> {
|
|
55
64
|
const collection = this.#db.collection(cmd.collection);
|
|
56
65
|
const result = await collection.insertOne(cmd.document);
|
|
57
66
|
yield { insertedId: result.insertedId };
|
|
58
67
|
}
|
|
59
68
|
|
|
60
|
-
async *#executeUpdateOneCommand(
|
|
61
|
-
cmd: AnyMongoWireCommand & { kind: 'updateOne' },
|
|
62
|
-
): AsyncIterable<UpdateOneResult> {
|
|
69
|
+
async *#executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult> {
|
|
63
70
|
const collection = this.#db.collection(cmd.collection);
|
|
64
71
|
const result = await collection.updateOne(cmd.filter, cmd.update);
|
|
65
72
|
yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };
|
|
66
73
|
}
|
|
67
74
|
|
|
68
|
-
async *#
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
async *#executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult> {
|
|
76
|
+
const collection = this.#db.collection(cmd.collection);
|
|
77
|
+
const result = await collection.insertMany(cmd.documents as Record<string, unknown>[]);
|
|
78
|
+
const insertedIds = Object.values(result.insertedIds);
|
|
79
|
+
yield { insertedIds, insertedCount: result.insertedCount };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async *#executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult> {
|
|
83
|
+
const collection = this.#db.collection(cmd.collection);
|
|
84
|
+
const result = await collection.updateMany(cmd.filter, cmd.update);
|
|
85
|
+
yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async *#executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult> {
|
|
71
89
|
const collection = this.#db.collection(cmd.collection);
|
|
72
90
|
const result = await collection.deleteOne(cmd.filter);
|
|
73
91
|
yield { deletedCount: result.deletedCount };
|
|
74
92
|
}
|
|
75
93
|
|
|
76
|
-
async *#
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
async *#executeDeleteManyCommand(cmd: DeleteManyWireCommand): AsyncIterable<DeleteManyResult> {
|
|
95
|
+
const collection = this.#db.collection(cmd.collection);
|
|
96
|
+
const result = await collection.deleteMany(cmd.filter);
|
|
97
|
+
yield { deletedCount: result.deletedCount };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async *#executeFindOneAndUpdateCommand(
|
|
101
|
+
cmd: FindOneAndUpdateWireCommand,
|
|
102
|
+
): AsyncIterable<Record<string, unknown>> {
|
|
103
|
+
const collection = this.#db.collection(cmd.collection);
|
|
104
|
+
const result = await collection.findOneAndUpdate(cmd.filter, cmd.update, {
|
|
105
|
+
returnDocument: 'after',
|
|
106
|
+
upsert: cmd.upsert,
|
|
107
|
+
});
|
|
108
|
+
if (result) {
|
|
109
|
+
yield result as Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async *#executeFindOneAndDeleteCommand(
|
|
114
|
+
cmd: FindOneAndDeleteWireCommand,
|
|
115
|
+
): AsyncIterable<Record<string, unknown>> {
|
|
116
|
+
const collection = this.#db.collection(cmd.collection);
|
|
117
|
+
const result = await collection.findOneAndDelete(cmd.filter);
|
|
118
|
+
if (result) {
|
|
119
|
+
yield result as Record<string, unknown>;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async *#executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row> {
|
|
79
124
|
const collection = this.#db.collection(cmd.collection);
|
|
80
125
|
const cursor = collection.aggregate(cmd.pipeline as Record<string, unknown>[]);
|
|
81
126
|
yield* cursor as AsyncIterable<Row>;
|