mopidy-musicbox-webclient icon indicating copy to clipboard operation
mopidy-musicbox-webclient copied to clipboard

Inability to setParameter or ordered by Id field

Open singlakarun opened this issue 3 years ago • 4 comments

This is pretty coming scenario to execute queries on Id field

// objectbox: entity
class MyEntity {
    var id: Id = 0
//more fields
}

let box: Box<MyEntity> = ...
let query = box.query {
     MyEntity.id.isEquals(to: 0)
}.ordered(by: MyEntity.id) --> COMPILATION ERROR here
.build()

query.setParameter(MyEntity.id, 0) --> COMPILATION ERROR here

singlakarun avatar May 14 '21 13:05 singlakarun

Some people say IDs should not used in queries at all as they should not represent any application data. What's your use case?

greenrobot avatar Jun 07 '21 08:06 greenrobot

I am storing chat messages in a table and wanted to extract the last message inserted. Doing it via timestamp might be inaccurate as theoretically there could be multiple messages generated in a millisecond. Only way out is to use my own auto increment column which I want to avoid. Also I wanted to sort the messages in the reverse insertion order.

singlakarun avatar Jun 07 '21 13:06 singlakarun

Yes, IDs "happen" to work for that local case. Technically, we don't give guarantees that this will stay like this forever, and, e.g. if you'd use Sync, it would break right away.

Other than that, we'll look into the compilation issue, of course. It will take some time though, as there are other things on our priority queue.

greenrobot avatar Jun 07 '21 14:06 greenrobot