Replies: 2 comments 2 replies
-
|
I came up with this workaround but it seems really weird that there wouldn't be a built-in function for this func testDB() {
users := make([]User, 0)
if err := db.NewSelect().Model(&users).OrderExpr("id ASC").Scan(ctx); err != nil {
panic(err)
}
if *debug {
log.Printf("Users: %v", users)
}
formattedData := []fixtureData{{Model: "User", Rows: users}}
data, err := yaml.Marshal(formattedData)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("config/test.yaml", data, fs.FileMode(0700))
if err != nil {
panic(err)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I agree that there should be some builtin function, but I am not sure about the API. Perhaps something like: enc := dbfixture.NewEncoder(writer)
if err := enc.Encode(users); err != nil {
panic(err)
}And it will not be much/any better than your function... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I've created queries for inserting users into my database, loosely based off of the basic example in the repository. I've been struggling to find how I'd actually save my database to a fixture file now, or just saving it overall. It doesn't seem to be in the docs, nor can I find the answer to this in the existing issues..
Beta Was this translation helpful? Give feedback.
All reactions