初始化Go学习项目
This commit is contained in:
28
go-gorm-demo/model_basic.go
Normal file
28
go-gorm-demo/model_basic.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// // User 模型
|
||||
//
|
||||
// type User struct {
|
||||
// ID uint `gorm:"primaryKey"`
|
||||
// Name string `gorm:"size:100;not null"`
|
||||
// Email string `gorm:"size:100;unique;not null"`
|
||||
// Age int `gorm:"default:0"`
|
||||
// Active bool `gorm:"default:true"`
|
||||
// CreatedAt time.Time
|
||||
// UpdatedAt time.Time
|
||||
// }
|
||||
func main() {
|
||||
db, _ := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
|
||||
|
||||
// 自动迁移(创建表)
|
||||
db.AutoMigrate(&User{})
|
||||
|
||||
fmt.Println("Table created successfully!")
|
||||
}
|
||||
Reference in New Issue
Block a user