Fix ordering and limit in query
This commit is contained in:
parent
38318556aa
commit
1e8a96ef20
@ -181,7 +181,7 @@ export function applyQueryNoFilterKV(
|
|||||||
): KV[] {
|
): KV[] {
|
||||||
// Order by
|
// Order by
|
||||||
if (query.orderBy) {
|
if (query.orderBy) {
|
||||||
allItems.sort((a, b) => {
|
allItems = allItems.sort((a, b) => {
|
||||||
const aVal = a.value;
|
const aVal = a.value;
|
||||||
const bVal = b.value;
|
const bVal = b.value;
|
||||||
for (const { expr, desc } of query.orderBy!) {
|
for (const { expr, desc } of query.orderBy!) {
|
||||||
|
@ -16,6 +16,28 @@ async function test(db: KvPrimitives) {
|
|||||||
filter: ["=", ["attr", "name"], ["string", "Peter"]],
|
filter: ["=", ["attr", "name"], ["string", "Peter"]],
|
||||||
});
|
});
|
||||||
assertEquals(results, [{ key: ["user", "peter"], value: { name: "Peter" } }]);
|
assertEquals(results, [{ key: ["user", "peter"], value: { name: "Peter" } }]);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
[{ key: ["user", "hank"], value: { name: "Hank" } }, {
|
||||||
|
key: ["user", "peter"],
|
||||||
|
value: { name: "Peter" },
|
||||||
|
}],
|
||||||
|
await datastore.query({
|
||||||
|
prefix: ["user"],
|
||||||
|
orderBy: [{ expr: ["attr", "name"], desc: false }],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
[{ key: ["user", "peter"], value: { name: "Peter" } }, {
|
||||||
|
key: ["user", "hank"],
|
||||||
|
value: { name: "Hank" },
|
||||||
|
}],
|
||||||
|
await datastore.query({
|
||||||
|
prefix: ["user"],
|
||||||
|
orderBy: [{ expr: ["attr", "name"], desc: true }],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
await datastore.batchSet<any>([
|
await datastore.batchSet<any>([
|
||||||
{ key: ["kv", "name"], value: "Zef" },
|
{ key: ["kv", "name"], value: "Zef" },
|
||||||
{ key: ["kv", "data"], value: new Uint8Array([1, 2, 3]) },
|
{ key: ["kv", "data"], value: new Uint8Array([1, 2, 3]) },
|
||||||
|
@ -83,7 +83,8 @@ export class DataStore {
|
|||||||
results.push(entry);
|
results.push(entry);
|
||||||
itemCount++;
|
itemCount++;
|
||||||
// Stop when the limit has been reached
|
// Stop when the limit has been reached
|
||||||
if (itemCount === limit) {
|
if (itemCount === limit && !query.orderBy) {
|
||||||
|
// Only break when not also ordering in which case we need all results
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ export async function widget(bodyText: string): Promise<WidgetContent> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// console.log("actual query", parsedQuery);
|
|
||||||
const eventName = `query:${parsedQuery.querySource}`;
|
const eventName = `query:${parsedQuery.querySource}`;
|
||||||
|
|
||||||
let resultMarkdown = "";
|
let resultMarkdown = "";
|
||||||
|
@ -7,7 +7,7 @@ Before we get to the nitty gritty, some _quick links_ for the impatient reader:
|
|||||||
Now that we got that out of the way let’s have a look at some of SilverBullet’s features.
|
Now that we got that out of the way let’s have a look at some of SilverBullet’s features.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* Runs in any modern browser (including on mobile) as a [[PWA]] in two potential [[Client Modes]] (_online_ and _synced_ mode), where the _synced mode_ enables **100% offline operation**, keeping a copy of content in the browser, syncing back to the server when a network connection is available.
|
* Runs in any modern browser (including on mobile) as a [[PWA]] in two [[Client Modes]] (_online_ and _synced_ mode), where the _synced mode_ enables **100% offline operation**, keeping a copy of content in the browser, syncing back to the server when a network connection is available.
|
||||||
* Provides an enjoyable [[Markdown]] writing experience with a clean UI, rendering text using [[Live Preview|live preview]], further **reducing visual noise** while still providing direct access to the underlying markdown syntax.
|
* Provides an enjoyable [[Markdown]] writing experience with a clean UI, rendering text using [[Live Preview|live preview]], further **reducing visual noise** while still providing direct access to the underlying markdown syntax.
|
||||||
* Supports wiki-style **page linking** using the `[[page link]]` syntax. Incoming links are indexed and appear as “Linked Mentions” at the bottom of the pages linked to thereby providing _bi-directional linking_.
|
* Supports wiki-style **page linking** using the `[[page link]]` syntax. Incoming links are indexed and appear as “Linked Mentions” at the bottom of the pages linked to thereby providing _bi-directional linking_.
|
||||||
* Optimized for **keyboard-based operation**:
|
* Optimized for **keyboard-based operation**:
|
||||||
@ -31,7 +31,7 @@ Here’s the kicker:
|
|||||||
|
|
||||||
That’s right, **this very website is powered by SilverBullet itself**. 🤯
|
That’s right, **this very website is powered by SilverBullet itself**. 🤯
|
||||||
|
|
||||||
On this site, everything is editable, just none of it syncs back (successfully) to the server. You are editing a local copy of this website, so changes do persist locally. (Note that a few other features including _directive_ updating are also disabled.)
|
On this site, everything is editable, just none of it syncs back (successfully) to the server. You are editing a local copy of this website, so changes do persist locally.
|
||||||
|
|
||||||
Don’t just sit there, try it!
|
Don’t just sit there, try it!
|
||||||
|
|
||||||
@ -43,7 +43,6 @@ Don’t just sit there, try it!
|
|||||||
* [ ] Tap this box 👈 to mark this task as done.
|
* [ ] Tap this box 👈 to mark this task as done.
|
||||||
* Start typing `:party` to trigger the emoji picker 🎉
|
* Start typing `:party` to trigger the emoji picker 🎉
|
||||||
* Type `/` somewhere in the text to invoke a **slash command**.
|
* Type `/` somewhere in the text to invoke a **slash command**.
|
||||||
* Hit `Cmd-p` (Mac) or `Ctrl-p` (Windows, Linux) to show a live preview for the current page on the side, if your brain doesn’t speak native Markdown yet.
|
|
||||||
* Click this button {[Editor: Toggle Vim Mode]} to toggle Vim mode
|
* Click this button {[Editor: Toggle Vim Mode]} to toggle Vim mode
|
||||||
* Open this site on your phone or tablet and... it just works!
|
* Open this site on your phone or tablet and... it just works!
|
||||||
* Are you using a browser with **PWA support** (e.g., any Chromium-based
|
* Are you using a browser with **PWA support** (e.g., any Chromium-based
|
||||||
@ -71,6 +70,13 @@ name: SilverBullet
|
|||||||
rating: 5
|
rating: 5
|
||||||
```
|
```
|
||||||
|
|
||||||
|
But where things get really interesting when using features like [[Live Queries]]. For instance, here are:
|
||||||
|
|
||||||
|
```query
|
||||||
|
page order by name desc limit 5
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Install SilverBullet
|
## Install SilverBullet
|
||||||
Has your mind been sufficiently blown to commit to an install? Took you long enough, alright then. Please proceed to the [[Install]] and enjoy!
|
Has your mind been sufficiently blown to commit to an install? Took you long enough, alright then. Please proceed to the [[Install]] and enjoy!
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user