qinglong-go/models/Apps.go

54 lines
1.4 KiB
Go
Raw Normal View History

2022-11-16 10:20:07 +00:00
package models
type Apps struct {
2023-09-04 06:02:25 +00:00
Id int `xorm:"pk autoincr int" json:"id,omitempty"`
2022-11-20 14:11:47 +00:00
Name string `xorm:"TEXT unique" json:"name,omitempty"`
Scopes []string `xorm:"JSON" json:"scopes,omitempty"`
ClientId string `xorm:"TEXT" json:"client_id,omitempty"`
ClientSecret string `xorm:"TEXT" json:"client_secret,omitempty"`
Tokens []string `xorm:"JSON" json:"tokens,omitempty"`
Createdat string `xorm:"not null DATETIME created" json:"createdat,omitempty"`
Updatedat string `xorm:"not null DATETIME updated" json:"updatedat,omitempty"`
}
func QueryApp() ([]*Apps, error) {
apps := make([]*Apps, 0)
session := engine.Table(new(Apps))
err := session.Find(&apps)
if err != nil {
return nil, err
}
return apps, err
}
func AddApp(app *Apps) (int, error) {
_, err := engine.Table(app).Insert(app)
if err != nil {
return 0, err
}
_, _ = engine.Where("name=?", app.Name).Get(app)
return app.Id, err
}
func GetApp(id int) (*Apps, error) {
app := new(Apps)
_, err := engine.ID(id).Get(app)
return app, err
}
func GetAppById(clientId string) (*Apps, error) {
app := new(Apps)
_, err := engine.Table(app).Where("client_id=?", clientId).Get(app)
return app, err
}
func UpdateApp(app *Apps) error {
_, err := engine.Table(app).ID(app.Id).AllCols().Update(app)
return err
}
func DeleteApp(id int) error {
_, err := engine.Table(new(Apps)).Delete(&Apps{Id: id})
return err
2022-11-16 10:20:07 +00:00
}