Skip to content

Commit 8179651

Browse files
committed
chore(orm): add GORM v2 PoC playground and validation script
1 parent dc841dd commit 8179651

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module github.com/YOUR_USERNAME/gorm_v2_migration
2+
3+
go 1.24.1
4+
5+
require (
6+
github.com/go-sql-driver/mysql v1.7.0 // indirect
7+
github.com/jinzhu/inflection v1.0.0 // indirect
8+
github.com/jinzhu/now v1.1.5 // indirect
9+
github.com/mattn/go-sqlite3 v1.14.28 // indirect
10+
golang.org/x/text v0.25.0 // indirect
11+
gorm.io/driver/mysql v1.5.7 // indirect
12+
gorm.io/driver/sqlite v1.5.7 // indirect
13+
gorm.io/gorm v1.26.1 // indirect
14+
)

playground/gorm_v2_migration/go.sum

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2025 The Kubeflow Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// This file is a minimal proof-of-concept (PoC) to verify that GORM v2's basic APIs
16+
// (Open, AutoMigrate, Create, Find, Update, Delete) work correctly with MySQL.
17+
// The goal is to ensure functional compatibility before integrating GORM v2 into the main codebase.
18+
19+
package main
20+
21+
import (
22+
"fmt"
23+
24+
"gorm.io/driver/mysql"
25+
"gorm.io/gorm"
26+
)
27+
28+
// Define model
29+
type User struct {
30+
ID uint `gorm:"primaryKey"`
31+
Name string
32+
Email string
33+
}
34+
35+
func main() {
36+
// Initialize GORM v2 with MySQL
37+
dsn := "testuser:testpw@tcp(127.0.0.1:3306)/testdb?charset=utf8mb4&parseTime=True&loc=Local"
38+
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
39+
if err != nil {
40+
panic("failed to connect database")
41+
}
42+
43+
// Auto-migrate table schema
44+
if err := db.AutoMigrate(&User{}); err != nil {
45+
panic("failed to migrate")
46+
}
47+
48+
// Insert data
49+
db.Create(&User{Name: "Alice", Email: "[email protected]"})
50+
51+
// Query data
52+
var user User
53+
db.First(&user, "name = ?", "Alice")
54+
fmt.Printf("User found: %+v\n", user)
55+
56+
// Find all users
57+
var users []User
58+
db.Find(&users)
59+
fmt.Printf("All users: %+v\n", users)
60+
61+
// Update user email
62+
db.Model(&user).Update("Email", "[email protected]")
63+
fmt.Printf("Updated user: %+v\n", user)
64+
65+
// Delete user
66+
db.Delete(&user)
67+
fmt.Println("User deleted.")
68+
69+
// Verify deletion
70+
var count int64
71+
db.Model(&User{}).Count(&count)
72+
fmt.Printf("Remaining users count: %d\n", count)
73+
74+
// Raw SQL: Show tables in MySQL
75+
var tableNames []string
76+
db.Raw("SHOW TABLES").Scan(&tableNames)
77+
fmt.Printf("Tables in DB (via Raw): %v\n", tableNames)
78+
}

0 commit comments

Comments
 (0)