Files
gochat/cmd/test_debug/main.go
T
2026-06-04 15:44:48 +08:00

39 lines
921 B
Go

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)
}