mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 04:32:01 +03:00
22 lines
591 B
TypeScript
22 lines
591 B
TypeScript
|
// Loaded from https://deno.land/x/dndb@0.2.4/src/methods/find.js
|
||
|
|
||
|
|
||
|
import { matches, project } from '../../deps.ts';
|
||
|
import { ReadFileStream } from '../storage.ts';
|
||
|
|
||
|
export default async (filename, query, projection) => {
|
||
|
let stream = new ReadFileStream(filename);
|
||
|
let found = [];
|
||
|
query = query || {};
|
||
|
stream.on('document', obj => {
|
||
|
if (matches(query , obj)){
|
||
|
obj = Object.keys(projection).length ? project(obj, projection) : obj;
|
||
|
found.push(obj)
|
||
|
}
|
||
|
})
|
||
|
return new Promise((resolve, reject) => {
|
||
|
stream.on('end', () => {
|
||
|
resolve(found);
|
||
|
})
|
||
|
})
|
||
|
}
|