You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disclaimer: I'm throwing an idea here, no clue if it is possible / relevant... anyway:
When using a DB such as storm as a persitance layer, you inevitably find yourself in a situation where you want to have relations between your various structs.
I think it would be nice to be able to declare a field of a struct as foreign (given it is a valid storm struct), and when saving it storm would store that field in a separate bucket.
type Line struct {
ID int `storm:"increment"`
Text string
}
type File struct {
ID int `storm:"increment"`
Lines []*Line `storm:"foreign"`
}
func main() {
db, err := storm.Open("stuff.db")
if err != nil {
log.Fatal(err)
}
l1 := Line{Text: "first line"}
l2 := Line{Text: "second line"}
file := File{Lines: []*Line{&l1, &l2}}
db.Save(&file)
// would store l1 and l2 in a "Line" bucket
var l3 Line
db.One("ID", 1, &l3)
// l3 == {1,"first line"}
l3.Text = "modified first line"
db.Save(&l3)
var file2 File
db.One("ID", 1, &file2)
// file2 == {1, {"modified first line", "second line"}}
}
The text was updated successfully, but these errors were encountered:
Another suggestion along that line: if a field of a struct is itself a struct and has an ID field, then automatically store that separately, and store the type + ID when serializing the database.
Disclaimer: I'm throwing an idea here, no clue if it is possible / relevant... anyway:
When using a DB such as storm as a persitance layer, you inevitably find yourself in a situation where you want to have relations between your various structs.
I think it would be nice to be able to declare a field of a struct as foreign (given it is a valid storm struct), and when saving it storm would store that field in a separate bucket.
The text was updated successfully, but these errors were encountered: