file change db
parent
71dfd15ed2
commit
5faadf20a8
@ -1,44 +1,65 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"goftp/gormdb"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
Id string `gorm:"primaryKey;size:20"`
|
||||
Downloadcount int64 `gorm:"size:20" json:"downloadcount"`
|
||||
Name string `gorm:"size:50" json:"fileName"`
|
||||
LastDownloadtime time.Time `json:"last_downloadtime"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
orm.RegisterModelWithPrefix("cm_", new(File))
|
||||
fmt.Println("File init()")
|
||||
gormdb.DB.AutoMigrate(&File{})
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Id string `orm:"pk" json:"id"`
|
||||
Downloadcount int64 `json:"downloadcount"`
|
||||
Name string `json:"fileName"`
|
||||
LastDownloadtime time.Time `json:"last_downloadtime"`
|
||||
// TableName 会将 User 的表名重写为 `user`
|
||||
func (File) TableName() string {
|
||||
return "file"
|
||||
}
|
||||
|
||||
func FindFileById(id string) (*File, error) {
|
||||
fileModel := new(File)
|
||||
err := orm.NewOrm().QueryTable(new(File)).Filter("id", id).One(fileModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fileModel, nil
|
||||
var file File
|
||||
gormdb.DB.First(&file, id)
|
||||
return &file, nil
|
||||
}
|
||||
|
||||
func FindFileByFileName(name string) (*File, error) {
|
||||
fileModel := new(File)
|
||||
err := orm.NewOrm().QueryTable(new(File)).Filter("name", name).One(fileModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fileModel, nil
|
||||
func FindFileByFileName(name string) *File {
|
||||
var file File
|
||||
gormdb.DB.Where("name = ?", name).First(&file)
|
||||
return &file
|
||||
|
||||
//fileModel := new(File)
|
||||
//err := orm.NewOrm().QueryTable(new(File)).Filter("name", name).One(fileModel)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//return fileModel, nil
|
||||
}
|
||||
|
||||
func UpdateFile(file *File) (int64, error) {
|
||||
return orm.NewOrm().Update(file)
|
||||
func UpdateFile(file *File) error {
|
||||
result := gormdb.DB.Save(&file)
|
||||
if result.Error != nil {
|
||||
fmt.Println("Failed to UpdateFile:", result.Error)
|
||||
return result.Error
|
||||
} else {
|
||||
fmt.Println("UpdateFile successfully!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertFile(file *File) (int64, error) {
|
||||
return orm.NewOrm().Insert(file)
|
||||
func InsertFile(file *File) error {
|
||||
result := gormdb.DB.Save(&file)
|
||||
if result.Error != nil {
|
||||
fmt.Println("Failed to create InsertFile:", result.Error)
|
||||
return result.Error
|
||||
} else {
|
||||
fmt.Println("InsertFile created successfully!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1,24 +1,44 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"fmt"
|
||||
"goftp/gormdb"
|
||||
)
|
||||
|
||||
type Ip struct {
|
||||
Id string `gorm:"primaryKey;size:20"`
|
||||
Ip string `gorm:"size:30"`
|
||||
Updatetime string `gorm:"size:30"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
orm.RegisterModelWithPrefix("cm_", new(Ip))
|
||||
fmt.Println("Ip init()")
|
||||
gormdb.DB.AutoMigrate(&Ip{})
|
||||
}
|
||||
|
||||
type Ip struct {
|
||||
Id string `orm:"pk" json:"id"`
|
||||
Ip string `json:"ip"`
|
||||
Updatetime string `json:"updatetime"`
|
||||
// TableName 会将 User 的表名重写为 `user`
|
||||
func (Ip) TableName() string {
|
||||
return "ip"
|
||||
}
|
||||
|
||||
func GetIpById(id string) string {
|
||||
ipModel := new(Ip)
|
||||
err := orm.NewOrm().QueryTable(new(Ip)).Filter("id", id).One(ipModel)
|
||||
if err != nil {
|
||||
return ""
|
||||
func SaveIp(ip *Ip) {
|
||||
result := gormdb.DB.Create(&ip)
|
||||
if result.Error != nil {
|
||||
fmt.Println("Failed to create Ip:", result.Error)
|
||||
} else {
|
||||
fmt.Println("Ip created successfully!")
|
||||
}
|
||||
return ipModel.Ip
|
||||
}
|
||||
|
||||
func GetIpById(id string) string {
|
||||
var ip Ip
|
||||
gormdb.DB.First(&ip, id)
|
||||
return ip.Ip
|
||||
|
||||
//ipModel := new(Ip)
|
||||
//err := orm.NewOrm().QueryTable(new(Ip)).Filter("id", id).One(ipModel)
|
||||
//if err != nil {
|
||||
// return ""
|
||||
//}
|
||||
//return ipModel.Ip
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue