You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
package repository |
|
|
|
import ( |
|
"sig-pub/pkg/data" |
|
"sig-pub/pkg/data/entity" |
|
"sig-pub/pkg/storage/persist" |
|
"sig-pub/pkg/utils/rands" |
|
) |
|
|
|
type UserRepository struct { |
|
db *persist.DB |
|
} |
|
|
|
func NewUserRepository(db *persist.DB) *UserRepository { |
|
return &UserRepository{ |
|
db: db, |
|
} |
|
} |
|
|
|
func (s *UserRepository) ListAllInstanceId() (insts []string, err error) { |
|
err = s.db.Select(&insts, `select inst_id from t_trade_instance where status != ?`, data.StatusDeleted) |
|
return |
|
} |
|
|
|
func (dao *UserRepository) FindByAccount(account string) (user *entity.User, err error) { |
|
user = &entity.User{} |
|
err = dao.db.Select(user, `select * from t_user where account=?`, account) |
|
return user, nil |
|
} |
|
|
|
func (dao *UserRepository) NextUid() (nextUid int64, err error) { |
|
var maxUid *int64 |
|
err = dao.db.Select(&maxUid, "select max(userid) from t_user") |
|
if err != nil { |
|
return |
|
} |
|
if maxUid == nil || *maxUid == 0 { |
|
maxUid = new(int64) |
|
*maxUid = 10000 |
|
} |
|
|
|
nextUid = *maxUid + rands.RandN(10) |
|
return |
|
} |
|
|
|
func (dao *UserRepository) Create(user *entity.User) (err error) { |
|
err = dao.db.Insert(user) |
|
return |
|
}
|
|
|