mirror of
https://github.com/swc-project/swc.git
synced 2024-12-30 00:52:29 +03:00
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
|
// Loaded from https://deno.land/x/mongo@v0.20.0/src/collection/commands/find.ts
|
||
|
|
||
|
|
||
|
import { CommandCursor, WireProtocol } from "../../protocol/mod.ts";
|
||
|
import { Document, FindOptions } from "../../types.ts";
|
||
|
|
||
|
interface FindCursorContext {
|
||
|
dbName: string;
|
||
|
collectionName: string;
|
||
|
protocol: WireProtocol;
|
||
|
options: FindOptions;
|
||
|
filter?: Document;
|
||
|
}
|
||
|
|
||
|
export class FindCursor<T> extends CommandCursor<T> {
|
||
|
#context: FindCursorContext;
|
||
|
|
||
|
private async executor() {
|
||
|
const { protocol, filter, dbName, collectionName, options } = this.#context;
|
||
|
const { cursor } = await protocol.commandSingle(dbName, {
|
||
|
find: collectionName,
|
||
|
filter,
|
||
|
batchSize: 1,
|
||
|
noCursorTimeout: true,
|
||
|
...options,
|
||
|
});
|
||
|
return {
|
||
|
...cursor,
|
||
|
id: cursor.id.toString(),
|
||
|
};
|
||
|
}
|
||
|
|
||
|
constructor(context: FindCursorContext) {
|
||
|
super(context.protocol, () => this.executor());
|
||
|
this.#context = context;
|
||
|
}
|
||
|
|
||
|
limit(limit: number): this {
|
||
|
this.#context.options.limit = limit;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
skip(skip: number): this {
|
||
|
this.#context.options.skip = skip;
|
||
|
return this;
|
||
|
}
|
||
|
}
|