objectbox-go

module
Version: v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2021 License: Apache-2.0

README

Do you ♥️ using ObjectBox?

We want to hear about your app! It will - literally - take just a minute, but help us a lot. Thank you!​ 🙏​

ObjectBox Go API

ObjectBox is a superfast database for objects. Using this Golang API, you can use ObjectBox as an embedded database in your Go application. A client/server mode will follow soon.

ObjectBox persists your native Go structs using a simple CRUD API:

id, err := box.Put(&Person{ FirstName: "Joe", LastName:  "Green" })

Want details? Read the docs or check out the API reference.

Latest release: v1.5.0 (2021-08-18)

Some features

  • Powerful queries
  • Relations (to-one, to-many)
  • Secondary indexes based on object properties
  • Asynchronous puts
  • Automatic model migration (no schema upgrade scripts etc.)
  • inline/prefix complex embedded structs (or you can use custom converters)
  • ObjectBox Sync: keeps data in sync between devices and servers.

Getting started

To install ObjectBox, execute the following command in your project directory. You can have a look at installation docs for more details and further instructions.

bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-go/main/install.sh)

To install ObjectBox Sync variant of the library, pass --sync argument to the command above:

bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-go/main/install.sh) --sync

You can run tests to validate your installation

go test github.com/objectbox/objectbox-go/...

With the dependencies installed, you can start adding entities to your project:

//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen
​
type Task struct {
	Id   uint64
	Text string
}

And run code generation in your project dir

go generate ./...

This generates a few files in the same folder as the entity - remember to add those to version control (e. g. git).

Once code generation finished successfully, you can start using ObjectBox:

obx := objectbox.NewBuilder().Model(ObjectBoxModel()).Build()
box := BoxForTask(obx) // Generated function to provide a Box for Task objects
id, _ := box.Put(&Task{ Text: "Buy milk" })

See the Getting started section of our docs for a more thorough intro.

Also, please have a look at the examples directory and for the API reference see ObjectBox GoDocs - and the sources in this repo.

Upgrading to a newer version

When you want to update, please re-run the entire installation process to ensure all components are updated:

  • ObjectBox itself (objectbox/objectbox-go)
  • Dependencies (flatbuffers)
  • ObjectBox library (libobjectbox.so|dylib; objectbox.dll)
  • ObjectBox code generator

This is important as diverging versions of any component might result in errors.

The install.sh script can also be used for upgrading:

bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-go/main/install.sh)

Afterwards, don't forget to re-run the code generation on your project

go generate ./...

License

Copyright 2018-2021 ObjectBox Ltd. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Directories

Path Synopsis
cmd
objectbox-gogen
Generates objectbox related code for ObjectBox entities (Go structs) It can be used by adding `//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen` comment inside a .go file containing the struct that you want to persist and executing `go generate` in the module Alternatively, you can run the command manually: objectbox-gogen [flags] {source-file} to generate the binding code or objectbox-gogen clean {path} to remove the generated files instead of creating them - this removes *.obx.go and objectbox-model.go but keeps objectbox-model.json path: * a source file path or a valid path pattern as accepted by the go tool (e.g.
Generates objectbox related code for ObjectBox entities (Go structs) It can be used by adding `//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen` comment inside a .go file containing the struct that you want to persist and executing `go generate` in the module Alternatively, you can run the command manually: objectbox-gogen [flags] {source-file} to generate the binding code or objectbox-gogen clean {path} to remove the generated files instead of creating them - this removes *.obx.go and objectbox-model.go but keeps objectbox-model.json path: * a source file path or a valid path pattern as accepted by the go tool (e.g.
examples
Package objectbox provides a super-fast, light-weight object persistence framework.
Package objectbox provides a super-fast, light-weight object persistence framework.
fbutils
Package fbutils provides utilities for the FlatBuffers in ObjectBox
Package fbutils provides utilities for the FlatBuffers in ObjectBox
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL