Replies: 4 comments 6 replies
-
Good point, this is currently not possible. I'll investigate if this can be added, perhaps also using collation specific sorting options.
This was implemented in the early versions of AceBase, but I decided to remove it because of these reasons:
However, this was all before AceBase was able to run in the browser, so I will take a look at enabling this option again for standalone db's.
You can use the reflection API to get all children and iterate yourself: const collectionRef = db.ref('books');
const childInfo = await collectionRef.reflect('children', { limit: 0, skip: 0 }); // Gets ALL child keys
for (let i = 0; i < childInfo.list.length; i++) {
const key = childInfo.list[i].key;
// Get child data, but only include their title and description properties
const snapshot = await collectionRef.child(key).get({ include: ['title', 'description'] });
// Do something with it
const book = snapshot.val();
console.log(`Got book "${book.title}": "${book.description}"`);
}Above solution also allows you to only load the data you are interested in, and you can stop iterating at will. |
Beta Was this translation helpful? Give feedback.
-
Update: I've implemented This is what will become possible: // Stream all books one at a time (loads all data for each book):
await db.ref('books').forEach(bookSnapshot => {
const book = bookSnapshot.val();
console.log(`Got book "${book.title}": "${book.description}"`);
});
// Now do the same but only load 'title' and 'description' of each book:
await db.ref('books').forEach(
{ include: ['title', 'description'] },
bookSnapshot => {
const book = bookSnapshot.val();
console.log(`Got book "${book.title}": "${book.description}"`);
}
);
// Query books, streaming the results one at a time:
await db.query('books')
.filter('category', '==', 'cooking')
.forEach(
{ include: ['title', 'description'] }, // (optional: only load these child keys of each book)
bookSnapshot => {
const book = bookSnapshot.val();
console.log(`Found cooking book "${book.title}": "${book.description}"`);
}
);Callbacks have the option to stop iteration by returning |
Beta Was this translation helpful? Give feedback.
-
Update: I've taken some time to look at case-insensitive sorting. The problem with this is that I'd also have to enable case-insensitivity in the matching and index engines, specifically for operators I'll keep you updated. |
Beta Was this translation helpful? Give feedback.
-
|
The new |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I see I can
query()using like which is case-insensitive however I can't see a way to perform a case-insensitive sort.Is it possible to use our own custom query filter function. Something like
filter(key, operator, compare)whereoperatorwould be a function we'd provide and you'd pass itkeyandcompare. In nanoSQL you can add query functions.Finally what is the best way to iterate all nodes in a path, one at a time which is performant and doesn't uses lots of memory (doesn't cache). ex. Like
db.query('songs')to get every node, one at a time.Beta Was this translation helpful? Give feedback.
All reactions