This commit is contained in:
Jay
2018-04-18 18:21:29 +08:00
parent d86e8e47f4
commit a971bd52d2
4 changed files with 91 additions and 10 deletions
+23 -8
View File
@@ -6,13 +6,13 @@ import (
// Account - Account table struct
type Account struct {
ID string `xorm:"id" cc:"id"`
ID string `xorm:"id <-" cc:"id"`
Account string `xorm:"account" cc:"account"`
Password string `xorm:"password" cc:"-"`
Nick string `xorm:"nick" cc:"nick"`
Email string `xorm:"email" cc:"email"`
Ctime time.Time `xorm:"ctime" cc:"ctime"`
Mtime time.Time `xorm:"mtime" cc:"mtime"`
Ctime time.Time `xorm:"ctime created" cc:"ctime"`
Mtime time.Time `xorm:"mtime updated" cc:"mtime"`
}
// GetAllAccount - all account
@@ -27,13 +27,28 @@ func GetAccount(account string) (acc *Account, err error) {
acc = &Account{
Account: account,
}
ok, err := x.Table("account").Get(acc)
if err != nil {
ok, err := acc.Get()
if err != nil || !ok {
return nil, err
}
if !ok {
return nil, nil
}
return
}
// Get -
func (a *Account) Get() (bool, error) {
ok, err := x.Table("account").Get(a)
if err != nil {
return false, err
}
return ok, nil
}
// Create -
func (a *Account) Create() error {
_, err := x.Table("account").Insert(a)
return err
}
+1
View File
@@ -13,5 +13,6 @@ var x *xorm.Engine
func NewDB() (*xorm.Engine, error) {
var err error
x, err = xorm.NewEngine("postgres", fmt.Sprintf("postgres://%s@%s/%s?sslmode=disable", "postgres", "localhost", "gallery"))
x.ShowSQL(true)
return x, err
}