objectbox / objectbox-go

Embedded Go Database, the fast alternative to SQLite, gorm, etc.
https://objectbox.io
Apache License 2.0
1.07k stars 46 forks source link

Self-assigned IDs #29

Closed ghost closed 3 years ago

ghost commented 3 years ago

ID is higher or equal to internal ID sequence: 3462622074874930866 (vs. 1). Use ID 0 (zero) to insert new entities.

vaind commented 3 years ago

This error happens when you call put with a non-existent ID, i.e. you're currently creating an object that wasn't before in the database. Does that describe your situation? If that's the case, see if you can change the object's ID to zero before calling box.Put(), it'll assign a new ID automatically

So-called self-assigned ID's aren't currently supported in objectbox-go binding

ghost commented 3 years ago

Hi @vaind and thanks for the quick reply. Yes, your correct: I was attempting to use my own generated IDs for objects. I was somehow under the impression that this is possible in the Go version too.

Any chance you guys could make IDs assignable in the Go library as well (I believe the Java version has this) ?

vaind commented 3 years ago

This is now available with v1.3.0:

type Entity struct {
    Id uint64 `objectbox:"id(assignable)"` 
}