mtfosbot/model/line_user.go

37 lines
813 B
Go
Raw Permalink Normal View History

2018-09-12 10:07:49 +00:00
package model
2018-09-26 08:17:54 +00:00
import (
"database/sql"
"time"
)
2018-09-12 10:07:49 +00:00
// LineUser -
type LineUser struct {
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"mtime"`
}
2018-09-19 16:17:00 +00:00
// GetLineUserByID -
func GetLineUserByID(id string) (u *LineUser, err error) {
2018-09-20 17:14:08 +00:00
u = &LineUser{}
err = x.Get(u, `select * from "public"."line_user" where "id" = $1`, id)
2018-09-26 08:17:54 +00:00
if err == sql.ErrNoRows {
return nil, nil
}
2018-09-19 16:17:00 +00:00
return
}
// Add -
func (p *LineUser) Add() (err error) {
_, err = x.NamedExec(`insert into "public"."line_user" ("id", "name") values (:id, :name)`, p)
return
}
2019-05-29 01:50:50 +00:00
// UpdateName -
func (p *LineUser) UpdateName() (err error) {
_, err = x.NamedExec(`update "public"."line_user" set "name" = :name, "mtime" = now() where "id" = :id`, p)
return
}