2023-09-10 15:39:34 +00:00
|
|
|
package db
|
|
|
|
|
2023-10-04 11:36:54 +00:00
|
|
|
func (db *DB) CreateUser(u *User) error {
|
2023-09-10 15:39:34 +00:00
|
|
|
_, err := db.Exec(
|
|
|
|
"INSERT INTO users(pubkey) VALUES ($1) ON CONFLICT(pubkey) DO UPDATE SET last_seen = CURRENT_TIMESTAMP",
|
|
|
|
u.Pubkey)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-10-04 13:37:04 +00:00
|
|
|
func (db *DB) FetchUser(pubkey string, u *User) error {
|
|
|
|
return db.QueryRow("SELECT pubkey, last_seen FROM users WHERE pubkey = $1", pubkey).Scan(&u.Pubkey, &u.LastSeen)
|
|
|
|
}
|
|
|
|
|
2023-10-04 11:36:54 +00:00
|
|
|
func (db *DB) UpdateUser(u *User) error {
|
2023-09-10 15:39:34 +00:00
|
|
|
_, err := db.Exec("UPDATE users SET last_seen = $1 WHERE pubkey = $2", u.LastSeen, u.Pubkey)
|
|
|
|
return err
|
|
|
|
}
|