@prisma-next/driver-mongo 0.4.0-dev.8 → 0.4.1
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/control.mjs +1 -1
- package/dist/{driver-info-Mhf3gwj-.mjs → driver-info-BLTErzWO.mjs} +2 -2
- package/dist/{driver-info-Mhf3gwj-.mjs.map → driver-info-BLTErzWO.mjs.map} +1 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +25 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/exports/index.ts +1 -1
- package/src/mongo-driver.ts +34 -14
package/dist/control.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as DRIVER_INFO } from "./driver-info-
|
|
1
|
+
import { t as DRIVER_INFO } from "./driver-info-BLTErzWO.mjs";
|
|
2
2
|
import { MongoClient } from "mongodb";
|
|
3
3
|
import { errorRuntime } from "@prisma-next/errors/execution";
|
|
4
4
|
import { redactDatabaseUrl } from "@prisma-next/utils/redact-db-url";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region package.json
|
|
2
|
-
var version = "0.4.
|
|
2
|
+
var version = "0.4.1";
|
|
3
3
|
|
|
4
4
|
//#endregion
|
|
5
5
|
//#region src/core/driver-info.ts
|
|
@@ -10,4 +10,4 @@ const DRIVER_INFO = {
|
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
export { DRIVER_INFO as t };
|
|
13
|
-
//# sourceMappingURL=driver-info-
|
|
13
|
+
//# sourceMappingURL=driver-info-BLTErzWO.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver-info-
|
|
1
|
+
{"version":3,"file":"driver-info-BLTErzWO.mjs","names":[],"sources":["../package.json","../src/core/driver-info.ts"],"sourcesContent":["","import { version } from '../../package.json' with { type: 'json' };\n\nexport const DRIVER_INFO = { name: 'Prisma', version } as const;\n"],"mappings":";;;;;ACEA,MAAa,cAAc;CAAE,MAAM;CAAU;CAAS"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { Db } from "mongodb";
|
|
1
2
|
import { MongoDriver } from "@prisma-next/mongo-lowering";
|
|
3
|
+
import { AnyMongoWireCommand } from "@prisma-next/mongo-wire";
|
|
2
4
|
|
|
3
5
|
//#region src/mongo-driver.d.ts
|
|
6
|
+
declare class MongoDriverImpl implements MongoDriver {
|
|
7
|
+
#private;
|
|
8
|
+
private constructor();
|
|
9
|
+
static fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl>;
|
|
10
|
+
static fromDb(db: Db): MongoDriverImpl;
|
|
11
|
+
execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row>;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
4
14
|
declare function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver>;
|
|
5
15
|
//#endregion
|
|
6
|
-
export { createMongoDriver };
|
|
16
|
+
export { MongoDriverImpl, createMongoDriver };
|
|
7
17
|
//# sourceMappingURL=index.d.mts.map
|
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":";;;;;cAsBa,eAAA,YAA2B;;EAA3B,QAAA,WAAgB,CAAA;EASuC,OAAA,cAAA,CAAA,GAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAR,OAAQ,CAAA,eAAA,CAAA;EAAR,OAAA,MAAA,CAAA,EAAA,EAMxC,EANwC,CAAA,EAMnC,eANmC;EAMxC,OAAA,CAAA,MAIJ,MAJI,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,WAAA,EAIkC,mBAJlC,CAAA,EAIwD,aAJxD,CAIsE,GAJtE,CAAA;EAAK,KAAA,CAAA,CAAA,EAgCR,OAhCQ,CAAA,IAAA,CAAA;;AAI6B,iBAgHhC,iBAAA,CAhHgC,GAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAgHgB,OAhHhB,CAgHwB,WAhHxB,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { t as DRIVER_INFO } from "./driver-info-
|
|
1
|
+
import { t as DRIVER_INFO } from "./driver-info-BLTErzWO.mjs";
|
|
2
2
|
import { MongoClient } from "mongodb";
|
|
3
3
|
|
|
4
4
|
//#region src/mongo-driver.ts
|
|
5
|
-
var MongoDriverImpl = class {
|
|
5
|
+
var MongoDriverImpl = class MongoDriverImpl {
|
|
6
6
|
#db;
|
|
7
7
|
#client;
|
|
8
8
|
constructor(db, client) {
|
|
9
9
|
this.#db = db;
|
|
10
10
|
this.#client = client;
|
|
11
11
|
}
|
|
12
|
+
static async fromConnection(uri, dbName) {
|
|
13
|
+
const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });
|
|
14
|
+
await client.connect();
|
|
15
|
+
return new MongoDriverImpl(client.db(dbName), client);
|
|
16
|
+
}
|
|
17
|
+
static fromDb(db) {
|
|
18
|
+
return new MongoDriverImpl(db, void 0);
|
|
19
|
+
}
|
|
12
20
|
execute(wireCommand) {
|
|
13
21
|
switch (wireCommand.kind) {
|
|
14
22
|
case "insertOne": return this.#executeInsertOneCommand(wireCommand);
|
|
@@ -27,16 +35,18 @@ var MongoDriverImpl = class {
|
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
async close() {
|
|
30
|
-
await this.#client
|
|
38
|
+
await this.#client?.close();
|
|
31
39
|
}
|
|
32
40
|
async *#executeInsertOneCommand(cmd) {
|
|
33
41
|
yield { insertedId: (await this.#db.collection(cmd.collection).insertOne(cmd.document)).insertedId };
|
|
34
42
|
}
|
|
35
43
|
async *#executeUpdateOneCommand(cmd) {
|
|
36
|
-
const result = await this.#db.collection(cmd.collection).updateOne(cmd.filter, cmd.update);
|
|
44
|
+
const result = await this.#db.collection(cmd.collection).updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });
|
|
37
45
|
yield {
|
|
38
46
|
matchedCount: result.matchedCount,
|
|
39
|
-
modifiedCount: result.modifiedCount
|
|
47
|
+
modifiedCount: result.modifiedCount,
|
|
48
|
+
upsertedCount: result.upsertedCount,
|
|
49
|
+
upsertedId: result.upsertedId ?? void 0
|
|
40
50
|
};
|
|
41
51
|
}
|
|
42
52
|
async *#executeInsertManyCommand(cmd) {
|
|
@@ -47,10 +57,12 @@ var MongoDriverImpl = class {
|
|
|
47
57
|
};
|
|
48
58
|
}
|
|
49
59
|
async *#executeUpdateManyCommand(cmd) {
|
|
50
|
-
const result = await this.#db.collection(cmd.collection).updateMany(cmd.filter, cmd.update);
|
|
60
|
+
const result = await this.#db.collection(cmd.collection).updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });
|
|
51
61
|
yield {
|
|
52
62
|
matchedCount: result.matchedCount,
|
|
53
|
-
modifiedCount: result.modifiedCount
|
|
63
|
+
modifiedCount: result.modifiedCount,
|
|
64
|
+
upsertedCount: result.upsertedCount,
|
|
65
|
+
upsertedId: result.upsertedId ?? void 0
|
|
54
66
|
};
|
|
55
67
|
}
|
|
56
68
|
async *#executeDeleteOneCommand(cmd) {
|
|
@@ -61,13 +73,14 @@ var MongoDriverImpl = class {
|
|
|
61
73
|
}
|
|
62
74
|
async *#executeFindOneAndUpdateCommand(cmd) {
|
|
63
75
|
const result = await this.#db.collection(cmd.collection).findOneAndUpdate(cmd.filter, cmd.update, {
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
upsert: cmd.upsert,
|
|
77
|
+
...cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {},
|
|
78
|
+
...cmd.sort != null ? { sort: cmd.sort } : {}
|
|
66
79
|
});
|
|
67
80
|
if (result) yield result;
|
|
68
81
|
}
|
|
69
82
|
async *#executeFindOneAndDeleteCommand(cmd) {
|
|
70
|
-
const result = await this.#db.collection(cmd.collection).findOneAndDelete(cmd.filter);
|
|
83
|
+
const result = await this.#db.collection(cmd.collection).findOneAndDelete(cmd.filter, { ...cmd.sort != null ? { sort: cmd.sort } : {} });
|
|
71
84
|
if (result) yield result;
|
|
72
85
|
}
|
|
73
86
|
async *#executeAggregateCommand(cmd) {
|
|
@@ -75,11 +88,9 @@ var MongoDriverImpl = class {
|
|
|
75
88
|
}
|
|
76
89
|
};
|
|
77
90
|
async function createMongoDriver(uri, dbName) {
|
|
78
|
-
|
|
79
|
-
await client.connect();
|
|
80
|
-
return new MongoDriverImpl(client.db(dbName), client);
|
|
91
|
+
return MongoDriverImpl.fromConnection(uri, dbName);
|
|
81
92
|
}
|
|
82
93
|
|
|
83
94
|
//#endregion
|
|
84
|
-
export { createMongoDriver };
|
|
95
|
+
export { MongoDriverImpl, createMongoDriver };
|
|
85
96
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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';\nimport { DRIVER_INFO } from './core/driver-info';\n\
|
|
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';\nimport { DRIVER_INFO } from './core/driver-info';\n\nexport class MongoDriverImpl implements MongoDriver {\n readonly #db: Db;\n readonly #client: MongoClient | undefined;\n\n private constructor(db: Db, client: MongoClient | undefined) {\n this.#db = db;\n this.#client = client;\n }\n\n static async fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl> {\n const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });\n await client.connect();\n return new MongoDriverImpl(client.db(dbName), client);\n }\n\n static fromDb(db: Db): MongoDriverImpl {\n return new MongoDriverImpl(db, undefined);\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, { upsert: cmd.upsert });\n yield {\n matchedCount: result.matchedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.upsertedCount,\n upsertedId: result.upsertedId ?? undefined,\n };\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, { upsert: cmd.upsert });\n yield {\n matchedCount: result.matchedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.upsertedCount,\n upsertedId: result.upsertedId ?? undefined,\n };\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 upsert: cmd.upsert,\n ...(cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {}),\n ...(cmd.sort != null ? { sort: cmd.sort } : {}),\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 ...(cmd.sort != null ? { sort: cmd.sort } : {}),\n });\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 return MongoDriverImpl.fromConnection(uri, dbName);\n}\n"],"mappings":";;;;AAsBA,IAAa,kBAAb,MAAa,gBAAuC;CAClD,CAASA;CACT,CAASC;CAET,AAAQ,YAAY,IAAQ,QAAiC;AAC3D,QAAKD,KAAM;AACX,QAAKC,SAAU;;CAGjB,aAAa,eAAe,KAAa,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AI,WAAW,IAAI,WAAW,CAC5B,UAAU,IAAI,SAAsC;;;AAKlF,eAAsB,kBAAkB,KAAa,QAAsC;AACzF,QAAO,gBAAgB,eAAe,KAAK,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/driver-mongo",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
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/
|
|
10
|
-
"@prisma-next/mongo-lowering": "0.4.
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/errors": "0.4.1",
|
|
10
|
+
"@prisma-next/mongo-lowering": "0.4.1",
|
|
11
|
+
"@prisma-next/mongo-wire": "0.4.1",
|
|
12
|
+
"@prisma-next/framework-components": "0.4.1",
|
|
13
|
+
"@prisma-next/utils": "0.4.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"mongodb-memory-server": "10.4.3",
|
package/src/exports/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createMongoDriver } from '../mongo-driver';
|
|
1
|
+
export { createMongoDriver, MongoDriverImpl } from '../mongo-driver';
|
package/src/mongo-driver.ts
CHANGED
|
@@ -20,15 +20,25 @@ import type {
|
|
|
20
20
|
import { type Db, MongoClient } from 'mongodb';
|
|
21
21
|
import { DRIVER_INFO } from './core/driver-info';
|
|
22
22
|
|
|
23
|
-
class MongoDriverImpl implements MongoDriver {
|
|
23
|
+
export class MongoDriverImpl implements MongoDriver {
|
|
24
24
|
readonly #db: Db;
|
|
25
|
-
readonly #client: MongoClient;
|
|
25
|
+
readonly #client: MongoClient | undefined;
|
|
26
26
|
|
|
27
|
-
constructor(db: Db, client: MongoClient) {
|
|
27
|
+
private constructor(db: Db, client: MongoClient | undefined) {
|
|
28
28
|
this.#db = db;
|
|
29
29
|
this.#client = client;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
static async fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl> {
|
|
33
|
+
const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });
|
|
34
|
+
await client.connect();
|
|
35
|
+
return new MongoDriverImpl(client.db(dbName), client);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static fromDb(db: Db): MongoDriverImpl {
|
|
39
|
+
return new MongoDriverImpl(db, undefined);
|
|
40
|
+
}
|
|
41
|
+
|
|
32
42
|
execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row> {
|
|
33
43
|
switch (wireCommand.kind) {
|
|
34
44
|
case 'insertOne':
|
|
@@ -58,7 +68,7 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
async close(): Promise<void> {
|
|
61
|
-
await this.#client
|
|
71
|
+
await this.#client?.close();
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
async *#executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult> {
|
|
@@ -69,8 +79,13 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
69
79
|
|
|
70
80
|
async *#executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult> {
|
|
71
81
|
const collection = this.#db.collection(cmd.collection);
|
|
72
|
-
const result = await collection.updateOne(cmd.filter, cmd.update);
|
|
73
|
-
yield {
|
|
82
|
+
const result = await collection.updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });
|
|
83
|
+
yield {
|
|
84
|
+
matchedCount: result.matchedCount,
|
|
85
|
+
modifiedCount: result.modifiedCount,
|
|
86
|
+
upsertedCount: result.upsertedCount,
|
|
87
|
+
upsertedId: result.upsertedId ?? undefined,
|
|
88
|
+
};
|
|
74
89
|
}
|
|
75
90
|
|
|
76
91
|
async *#executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult> {
|
|
@@ -82,8 +97,13 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
82
97
|
|
|
83
98
|
async *#executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult> {
|
|
84
99
|
const collection = this.#db.collection(cmd.collection);
|
|
85
|
-
const result = await collection.updateMany(cmd.filter, cmd.update);
|
|
86
|
-
yield {
|
|
100
|
+
const result = await collection.updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });
|
|
101
|
+
yield {
|
|
102
|
+
matchedCount: result.matchedCount,
|
|
103
|
+
modifiedCount: result.modifiedCount,
|
|
104
|
+
upsertedCount: result.upsertedCount,
|
|
105
|
+
upsertedId: result.upsertedId ?? undefined,
|
|
106
|
+
};
|
|
87
107
|
}
|
|
88
108
|
|
|
89
109
|
async *#executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult> {
|
|
@@ -103,8 +123,9 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
103
123
|
): AsyncIterable<Record<string, unknown>> {
|
|
104
124
|
const collection = this.#db.collection(cmd.collection);
|
|
105
125
|
const result = await collection.findOneAndUpdate(cmd.filter, cmd.update, {
|
|
106
|
-
returnDocument: 'after',
|
|
107
126
|
upsert: cmd.upsert,
|
|
127
|
+
...(cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {}),
|
|
128
|
+
...(cmd.sort != null ? { sort: cmd.sort } : {}),
|
|
108
129
|
});
|
|
109
130
|
if (result) {
|
|
110
131
|
yield result as Record<string, unknown>;
|
|
@@ -115,7 +136,9 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
115
136
|
cmd: FindOneAndDeleteWireCommand,
|
|
116
137
|
): AsyncIterable<Record<string, unknown>> {
|
|
117
138
|
const collection = this.#db.collection(cmd.collection);
|
|
118
|
-
const result = await collection.findOneAndDelete(cmd.filter
|
|
139
|
+
const result = await collection.findOneAndDelete(cmd.filter, {
|
|
140
|
+
...(cmd.sort != null ? { sort: cmd.sort } : {}),
|
|
141
|
+
});
|
|
119
142
|
if (result) {
|
|
120
143
|
yield result as Record<string, unknown>;
|
|
121
144
|
}
|
|
@@ -129,8 +152,5 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
129
152
|
}
|
|
130
153
|
|
|
131
154
|
export async function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver> {
|
|
132
|
-
|
|
133
|
-
await client.connect();
|
|
134
|
-
const db = client.db(dbName);
|
|
135
|
-
return new MongoDriverImpl(db, client);
|
|
155
|
+
return MongoDriverImpl.fromConnection(uri, dbName);
|
|
136
156
|
}
|