Git Product home page Git Product logo

Comments (3)

vaind avatar vaind commented on May 20, 2024

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.

from objectbox-go.

vaind avatar vaind commented on May 20, 2024

Updated docs: https://golang.objectbox.io/custom-types#queries

from objectbox-go.

rerosum avatar rerosum commented on May 20, 2024

Thanks for the clarification.

from objectbox-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.