I'm using this ORM library for PostgreSQL: https://godoc.org/github.com/go-pg/pg#example-DB-Select and I'm having an odd issue which I don't understand.
I'm trying to SELECT
data from my settings
table to later update that value with a function.
package settingsmodel
import (
. "database"
)
type Settings struct {
Id int64
SiteName string
}
func Set(newValue string) bool {
site := &Settings {
SiteName: "MySite",
}
err := Db.Select(&site)
if err != nil {
panic(err) // This is where it panics
}
site.SiteName = newValue
err = Db.Update(site)
if err != nil {
panic(err)
}
return true
}
The error I'm getting is panic: pg: Model(unsupported *settingsmodel.Settings)
I have another function (in the same file) where I get the site name and it works perfectly fine:
func Get() string {
var site Settings
err := Db.Model(&site).First()
if err != nil {
panic(err)
}
return site.SiteName
}
I really don't understand why it's not working. Any help? Thanks!