instantdb / instant

Instant is a modern Firebase. We make you productive by giving your frontend a real-time database.
https://instantdb.com
Apache License 2.0
6.7k stars 184 forks source link

Custom `order` conditions #149

Open anyinfa opened 2 months ago

anyinfa commented 2 months ago

Currently, sorting is only supported based on the internal field serverCreatedAt. Will custom field sorting be added in the future?

order: {
  // serverCreatedAt: 'desc',
  updatedAt: 'desc'
}

And multi-field sorting?

order: [
  { updatedAt: 'desc' },
  { name: 'asc' }
]
dwwoelfel commented 2 months ago

We will be adding ordering on user-defined fields.

They're not implemented yet because the values are stored in the database as JSON and we wouldn't be able to efficiently order the rows.

The data is stored in the triples table as entity_id, attribute_id, value_json triples. The plan is to add partial indexes to the triples table, one for each type that we support. If you want to order by a custom string attribute, we'll index it in the string partial index and then the order by will be efficient.

montnyc commented 1 month ago

Do y'all have a public roadmap for when some of these things will be added? Only ordering by serverCreatedAt is fine for now but not ideal. Would love to be able to filter on other attributes. Also would love to be able to use $lte etc, especially for dates.

isaachinman commented 5 days ago

Any update on this? This is a complete blocker for our use case, and I imagine many others.

We have collections that contain many thousands of values and cannot reasonably be sorted in memory – let alone handling pagination, etc.

stopachka commented 4 days ago

Hey team! Since we launched strong types yesterday, order is the next big thing!

You can follow along in this PR: https://github.com/instantdb/instant/pull/564