update
This commit is contained in:
+23
-8
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user