To get started with ObjectBox you can get the repository code as usual with
go get and install the few prerequisites - flatbuffers, ObjectBox pre-compiled library and code generator generator.
go get github.com/objectbox/objectbox-go/...go get github.com/google/flatbuffers/gomkdir objectboxlib && cd objectboxlibcurl https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh > download.shbash download.sh # press y to install to /usr/local/libgo install github.com/objectbox/objectbox-go/cmd/objectbox-gogen/go test github.com/objectbox/objectbox-go/...
At this point you should see the GO tests passing and you can start working with ObjectBox in your project:
In case you're interested or are having trouble with the installation, the following sections provide more details on the procedure.
The main prerequisite to using the Go APIs is the ObjectBox binary library (.so, .dylib, .dll depending on your platform) which actually implements the database functionality. In the ObjectBox C repository, you should find a
download.sh script you can run.
curl https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh > download.shbash download.sh
Follow the instructions and type
Y when it asks you if it should install the library.
curl is absent on your system you can use wget instead:
There are some additional steps necessary for windows.
We are using
cgo which requires you to have MinGW gcc in PATH, e. g. http://tdm-gcc.tdragon.net/
In order to compile your program, you need to copy the downloaded
objectbox.dll to the MinGW library directory, e. g.
To run the program, you either need to have the
objectbox.dll library in the same folder as the compiled program, or copy it to the system library directory
ObjectBox can generate Go bindings (structs & functions) for your data entities. While you certainly could do this manually, it would be quite tedious and that's why we provide a bindings generator. This is a command line program you can compile and install just by running
go install github.com/objectbox/objectbox-go/cmd/objectbox-gogen/
With the generator installed, you can just write a special comment
//go:generate objectbox-gogen to the
.go file where your entity/entities structs are defined and execute
go generate on that folder or alternatively you can run the following command on your entire project (execute it in your project root):
go generate ./...