diff --git a/src/index.ts b/src/index.ts index 0ced148..31a883e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -331,35 +331,7 @@ async function createDoubleDb(dataDirectory: string): Promise { async function query(queryObject?: object, options?: { limit?: number; offset?: number; sort?: { [key: string]: 1 | -1 }; project?: { [key: string]: 1 } }): Promise { if (!queryObject || Object.keys(queryObject).length === 0) { - const allIds = await getAllIds(); - let results = await Promise.all([...allIds].map(id => read(id))); - const offset = options?.offset ?? 0; - const limit = options?.limit ?? results.length; - - if (options?.sort) { - const sortFields = Object.entries(options.sort); - results.sort((a, b) => { - for (const [field, direction] of sortFields) { - if (a[field] < b[field]) return direction === 1 ? -1 : 1; - if (a[field] > b[field]) return direction === 1 ? 1 : -1; - } - return 0; - }); - } - - if (options?.project) { - results = results.map(doc => { - const projected: Document = {}; - for (const field of Object.keys(options.project)) { - if (field in doc) { - projected[field] = doc[field]; - } - } - return projected; - }); - } - - return results.filter((doc): doc is Document => doc !== undefined).slice(offset, offset + limit); + queryObject = { id: { $exists: true } }; } let resultIds = new Set(); diff --git a/test/query.ts b/test/query.ts index f79ab01..2fa50c7 100644 --- a/test/query.ts +++ b/test/query.ts @@ -27,6 +27,20 @@ test('empty query', async () => { await db.close(); }); +test('special characters', async () => { + const db = await setupTestDb(); + await db.insert({ id: 'users/mark', name: 'Mark' }); + await db.insert({ id: 'users/joe', name: 'Joe' }); + await db.insert({ id: 'users/mary', name: 'Mary' }); + await db.insert({ id: 'groups/standard', name: 'Standard' }); + await db.insert({ id: 'groups/admin', name: 'Admin' }); + await db.insert({ id: 'rootD', name: 'rootD' }); + + const result = await db.query(); + assert.strictEqual(result.length, 6); + await db.close(); +}); + test('$sw operator on string', async () => { const db = await setupTestDb(); await db.insert({ value: 'alpha' });