1
0

Fix ordering and limit in query

This commit is contained in:
Zef Hemel 2023-10-03 16:54:03 +02:00
parent 38318556aa
commit 1e8a96ef20
5 changed files with 34 additions and 6 deletions

View File

@ -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!) {

View File

@ -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]) },

View File

@ -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;
} }
} }

View File

@ -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 = "";

View File

@ -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 lets have a look at some of SilverBullets features. Now that we got that out of the way lets have a look at some of SilverBullets 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 @@ Heres the kicker:
Thats right, **this very website is powered by SilverBullet itself**. 🤯 Thats 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.
Dont just sit there, try it! Dont just sit there, try it!
@ -43,7 +43,6 @@ Dont 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 doesnt 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!