This commit is contained in:
Jay
2018-04-12 17:41:21 +08:00
parent 078461b8cd
commit 5484da1212
5 changed files with 65 additions and 4 deletions
+29
View File
@@ -0,0 +1,29 @@
package models
import (
"time"
)
// Account - Account table struct
type Account struct {
ID string `xorm:"id"`
Account string `xorm:"account"`
Password string `xorm:"password"`
Nick string `xorm:"nick"`
Email string `xorm:"email"`
Ctime time.Time `xorm:"ctime"`
Mtime time.Time `xorm:"mtime"`
}
// GetAllAccount - all account
func GetAllAccount() ([]Account, error) {
var accs []Account
err := x.Table("account").Find(&accs)
return accs, err
}
// Get - get account info
func (c *Account) Get() error {
_, err := x.Table("account").Get(c)
return err
}
+17
View File
@@ -0,0 +1,17 @@
package models
import (
"fmt"
"github.com/go-xorm/xorm"
_ "github.com/lib/pq"
)
var x *xorm.Engine
// NewDB - db object
func NewDB() (*xorm.Engine, error) {
var err error
x, err = xorm.NewEngine("postgres", fmt.Sprintf("postgres://%s@%s/%s?sslmode=disable", "postgres", "localhost", "gallery"))
return x, err
}