Gizmo is a library that allows for the creation of versioned, view-aware objects written in a relational style. It is a simple, safe, and productive framework for creating content that will be present data different in different situations and is automatically versioned on every change.
-
Download and install it:
$ go get github.com/FoxComm/gizmo
-
Run the database migrations:
$ gizmo setup
-
Import gizmo to your code:
import "github.com/FoxComm/gizmo"
-
Add
gizmo.EntityObject
to the struct you want to save:type Product struct { gizmo.EntityObject Title string Description string }
-
Create
Manager
and connect to your database:dbHost := "127.0.0.1" dbName := "gizmo" dbUser := "gizmo" dbPassword := "I<3Gizmo" mgr, err := gizmo.NewManager(dbHost, dbName, dbUser, dbPassword)
-
Save a struct implementing
EntityObject
usingManager
:p := Product{ Title: "Some product", Description: "A product for demo purposes", } viewID := 1 saved, err := mgr.Create(p, viewID)
-
Retrieve the struct based on it's ID and view ID:
id := 1 viewID := 1 product := Product{} err := mgr.FindByID(id, viewID, &product)