add model
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Account - table
|
||||
type Account struct {
|
||||
ID string `db:"id"`
|
||||
Account string `db:"account"`
|
||||
Password string `db:"password"`
|
||||
Ctime time.Time `db:"ctime"`
|
||||
Mtime time.Time `db:"mtime"`
|
||||
}
|
||||
|
||||
// GetAllAccount -
|
||||
func GetAllAccount() (accs []Account, err error) {
|
||||
err = x.Select(&accs, "select * from public.account order by ctime asc")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetAccount -
|
||||
func GetAccount(account string) (acc *Account, err error) {
|
||||
err = x.Select(acc, `select * from "public"."account" where "account" = $1`, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ var x *sqlx.DB
|
||||
func NewDB() (*sqlx.DB, error) {
|
||||
var err error
|
||||
connStr := fmt.Sprintf("user=%s host=%s sslmode=disable dbname=%s port=%d", "postgres", "localhost", "mtfosbot", 5432)
|
||||
x, err := sqlx.Open("postgres", connStr)
|
||||
x, err = sqlx.Connect("postgres", connStr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user