Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect result when querying against date field #19

Closed
rerosum opened this issue Jan 7, 2020 · 3 comments
Closed

Incorrect result when querying against date field #19

rerosum opened this issue Jan 7, 2020 · 3 comments

Comments

@rerosum
Copy link

rerosum commented Jan 7, 2020

Please see attached sample project with failing test case.
testObjectBox.zip

@vaind
Copy link
Collaborator

vaind commented Jan 8, 2020

Go's time.Time struct is a complex type and requires a "converter" to store in the database. This converter is (as of ObjectBox Go 1.1) assigned automatically and used when storing and retrieving the data.

However, the query expects the already converted value (see func (property PropertyInt64) GreaterThan(value int64) Condition). There are no methods generated for the custom/complex type when using converters - the query methods expect the actual stored type & data.

Therefore, the usage in the failing test should look like this instead:

func TestGreaterThanDate(t *testing.T) {
	storedTime, err := objectbox.TimeInt64ConvertToDatabaseValue(t2)
	if err != nil {
		t.Error(err)
	}
	q := personBox.Query(
		person.Person_.Time.GreaterThan(storedTime),
		person.Person_.Time.OrderAsc(),
	)
	people, _ := q.Find()
	if people[0].Time.Unix() != t1.Unix() {
		t.Errorf("Expected t1 (%d) but got %d\nt0: %d, t1: %d, t2: %d", t1.Unix(), people[0].Time.Unix(), t0.Unix(), t1.Unix(), t2.Unix())
	}
}

With TimeInt64ConvertToDatabaseValue being one of the few built in converters you can use instead of defining a custom one.

Thanks for pointing this out. We will update the docs to mention this and also create an internal issue to track whether there can be something helpful done using code generation.

@vaind
Copy link
Collaborator

vaind commented Jan 8, 2020

@rerosum
Copy link
Author

rerosum commented Jan 9, 2020

Thanks for the clarification.

@rerosum rerosum closed this as completed Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants