Skip to content

Commit 18137ba

Browse files
committed
MongoClient: db function is not an effectful operation like mongodb driver
1 parent 787620c commit 18137ba

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

examples/copy-between-dbs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type MyType = Schema.Schema.Type<typeof MyType>
1616

1717
const program = Effect.gen(function*(_) {
1818
const sourceInstance = yield* _(MongoClient.connect("mongodb://localhost:27017"))
19-
const sourceDb = yield* _(MongoClient.db(sourceInstance, "source"))
19+
const sourceDb = MongoClient.db(sourceInstance, "source")
2020
const sourceCollection = yield* _(Db.documentCollection(sourceDb, "records"))
2121
const sourceItems = yield* _(
2222
DocumentCollection.find(sourceCollection),
@@ -25,7 +25,7 @@ const program = Effect.gen(function*(_) {
2525
)
2626

2727
const destinationInstance = yield* _(MongoClient.connect("mongodb://localhost:27017"))
28-
const destinationDb = yield* _(MongoClient.db(destinationInstance, "destination"))
28+
const destinationDb = MongoClient.db(destinationInstance, "destination")
2929
const destinationCollection = yield* _(Db.collection(destinationDb, "records", MyType))
3030

3131
yield* _(Collection.insertMany(destinationCollection, sourceItems))

examples/elaborate-stream-with-partitioned-errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type MyType = Schema.Schema.Type<typeof MyType>
1818

1919
const program = Effect.gen(function*(_) {
2020
const sourceInstance = yield* _(MongoClient.connect("mongodb://localhost:27017"))
21-
const sourceDb = yield* _(MongoClient.db(sourceInstance, "source"))
21+
const sourceDb = MongoClient.db(sourceInstance, "source")
2222
const sourceCollection = yield* _(Db.documentCollection(sourceDb, "records"))
2323

2424
yield* _(

src/Db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const fromEffect = <DbK extends string, MongoClientK extends string, E =
7171
const dbName_ = yield* _(dbName)
7272
const db = yield* _(
7373
client,
74-
Effect.flatMap((client) => MongoClient.db(client, dbName_)),
74+
Effect.map((client) => MongoClient.db(client, dbName_)),
7575
Effect.cached
7676
)
7777
return dbTag.of({ db } as DbService<DbK>) // TODO fix cast using branded ctor

src/MongoClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export const connect = (url: string, options?: MongoClientOptions) =>
1818
)
1919

2020
export const db: {
21-
(dbName?: string, options?: DbOptions): (client: MongoClient) => Effect.Effect<Db>
22-
(client: MongoClient, dbName?: string, options?: DbOptions): Effect.Effect<Db>
21+
(dbName?: string, options?: DbOptions): (client: MongoClient) => Db
22+
(client: MongoClient, dbName?: string, options?: DbOptions): Db
2323
} = F.dual(
2424
(args) => isMongoClient(args[0]),
25-
(client: MongoClient, dbName?: string, options?: DbOptions) => Effect.sync(() => client.db(dbName, options))
25+
(client: MongoClient, dbName?: string, options?: DbOptions) => client.db(dbName, options)
2626
)
2727

2828
const isMongoClient = (x: unknown) => x instanceof MongoClient_

0 commit comments

Comments
 (0)