second commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gochat/gochat/internal/model"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := gorm.Open(sqlite.Open("file::memory:"), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
db.AutoMigrate(&model.DashboardApp{})
|
||||
|
||||
// Create an app with Active=false
|
||||
app := &model.DashboardApp{
|
||||
AccountID: 1,
|
||||
Title: "InactiveApp",
|
||||
Kind: "frame",
|
||||
Active: model.BoolPtr(false),
|
||||
Content: json.RawMessage(`[]`),
|
||||
}
|
||||
result := db.Select("AccountID", "UserID", "Title", "Description",
|
||||
"Icon", "URL", "Kind", "Content", "Active").Create(app)
|
||||
fmt.Printf("Create error: %v\n", result.Error)
|
||||
fmt.Printf("App Active after create: %v\n", app.Active)
|
||||
|
||||
// Read it back
|
||||
var found model.DashboardApp
|
||||
db.First(&found, app.ID)
|
||||
fmt.Printf("Found Active: %v\n", found.Active)
|
||||
}
|
||||
Reference in New Issue
Block a user