Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
🐛 sort
Browse files Browse the repository at this point in the history
  • Loading branch information
cedriking committed Apr 20, 2021
1 parent 6fccebf commit 5a8c583
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/__tests__/ardb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,25 @@ test('exclude', async () => {
expect(res2[0].node.owner).not.toHaveProperty('address');
expect(res2[0].node.owner).toHaveProperty('key');
});

test('order', async () => {
let res = await ardb
.search('transactions')
.appName('SmartWeaveAction')
.tag('Type', 'ArweaveActivity')
.only('id')
.sort('HEIGHT_ASC')
.find();

expect(res[0].node.id).toBe('5AYV-RdPCoyfjeeabHVnDGvXrFNM5azcTlkNpp7RQhE');

res = await ardb
.search('transactions')
.appName('SmartWeaveAction')
.tag('Type', 'ArweaveActivity')
.only('id')
.sort('HEIGHT_DESC')
.find();

expect(res[0].node.id).not.toBe('5AYV-RdPCoyfjeeabHVnDGvXrFNM5azcTlkNpp7RQhE');
});
5 changes: 4 additions & 1 deletion src/ardb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ export default class ArDB {
this.options = { id: this.options.id };
}

let params: string = JSON.stringify(this.options, null, 2).replace(/"([^"]+)":/gm, '$1: ');
let params: string = JSON.stringify(this.options, null, 2)
.replace(/"([^"]+)":/gm, '$1: ')
.replace('"HEIGHT_DESC"', 'HEIGHT_DESC')
.replace('"HEIGHT_ASC"', 'HEIGHT_ASC');
params = params.substring(1, params.length - 1);

let fields: string = '';
Expand Down

0 comments on commit 5a8c583

Please sign in to comment.