Open thanhnguyen2187 opened 4 months ago
There isn't an officially supported way to do this right now. But we have ideas for how to support these sorts of transformations in the query api in the future.
For now you have a few options:
Sort on your results in javascript - this is simple but you won't be able to leverage additional apis in the query engine like limit
Manually maintain a computed attribute
Support for computed attributes is on our short term roadmap, but for now you need to manage them manually. You'll create a new attribute attr_lower
and you'll have to manually maintain the invariant that attr_lower === lowercase(attr)
. Specifically when you mutateattr
with insert
and update
you'll need to manually mutate the attr_lower
attribute.
const text = 'AbC';
await client.insert('collection', { attr: text, attr_lower: lowercase(text) });
await client.update('collection', 'id', (entity) => {
const updatedText = 'XyZ';
entity.attr = updatedText;
entity.attr_lower = lowercase(updatedText);
});
That should allow you to fully use the query engine client.query('collection').order('attr_lower', 'ASC').limit(10)
.
We discussed this approach in our Discord recently as well: https://discord.com/channels/1138467878623006720/1138467879113728033/1256648644736712715
Other features on our short term roadmap like triggers could also be helpful here eventually.
I'll leave this open for others to share any ideas.
related to this: localeCompare for numerical string sorting
Hi. I'm trying to use
query.order
, but it seems like it is case-sensitive (A...
comes beforea...
). Is there anyway to make the query case-insensitive (a...
andA...
are treated the same, but they come beforeb...
)? Thanks!