52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package db
|
|
|
|
import "time"
|
|
|
|
func Session_UpdateLastSeenAt(
|
|
tx TX,
|
|
id string,
|
|
) (err error) {
|
|
_, err = tx.Exec("UPDATE sessions SET LastSeenAt=? WHERE SessionID=?", time.Now().Unix(), id)
|
|
return err
|
|
}
|
|
|
|
func Session_SetSignedIn(
|
|
tx TX,
|
|
id string,
|
|
) (err error) {
|
|
_, err = tx.Exec("UPDATE sessions SET SignedIn=1 WHERE SessionID=?", id)
|
|
return err
|
|
}
|
|
|
|
func Session_DeleteBefore(
|
|
tx TX,
|
|
timestamp int64,
|
|
) (err error) {
|
|
_, err = tx.Exec("DELETE FROM sessions WHERE LastSeenAt<?", timestamp)
|
|
return err
|
|
}
|
|
|
|
func Config_UpdatePassword(
|
|
tx TX,
|
|
pwdHash []byte,
|
|
) (err error) {
|
|
_, err = tx.Exec("UPDATE config SET Password=? WHERE ConfigID=1", pwdHash)
|
|
return err
|
|
}
|
|
|
|
func Peer_ListAll(tx TX) ([]*Peer, error) {
|
|
return Peer_List(tx, Peer_SelectQuery)
|
|
}
|
|
|
|
func Peer_GetByAPIKey(tx TX, apiKey string) (*Peer, error) {
|
|
return Peer_GetWhere(
|
|
tx,
|
|
Peer_SelectQuery+` WHERE APIKey=?`,
|
|
apiKey)
|
|
}
|
|
|
|
func Peer_Exists(tx TX, ip byte) (exists bool, err error) {
|
|
err = tx.QueryRow(`SELECT EXISTS(SELECT 1 FROM peers WHERE PeerIP=?)`, ip).Scan(&exists)
|
|
return
|
|
}
|