summaryrefslogtreecommitdiff
path: root/db/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'db/db.go')
-rw-r--r--db/db.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/db/db.go b/db/db.go
index 4824a6d..d9faff3 100644
--- a/db/db.go
+++ b/db/db.go
@@ -2,6 +2,7 @@ package db
import (
"os"
+ "time"
"io/fs"
"errors"
"database/sql"
@@ -19,11 +20,13 @@ type User struct {
type Session struct {
Id string
- UserId string
+ UserId int
+ Created time.Time
+ Modified time.Time
}
type Endpoint struct {
- Id string
+ Id int
Name string
Path string
Address string
@@ -45,6 +48,7 @@ type Model interface {
CreateSession(user User) (Session, error)
DeleteSession(session Session) error
CheckSession(session Session) (bool, error)
+ CleanSessions(maxIdle time.Duration) error
AllSessions() ([]Session, error)
CreateEndpoint(name, path, address string) (Endpoint, error)
@@ -52,6 +56,7 @@ type Model interface {
GetEndpointByName(name string) (Endpoint, error)
GetEndpointByPath(path string) (Endpoint, error)
GetEndpointByAddress(address string) (Endpoint, error)
+ AllEndpoints() ([]Endpoint, error)
}
@@ -100,7 +105,7 @@ func (p *Phlox) Create(filename string) error {
insert into schema values(0);
create table users (userid integer not null primary key, username string, passwordhash string, salt string);
- create table sessions (sessionid string not null primary key, userid integer, foreign key(userid) references users(userid));
+ create table sessions (sessionid string not null primary key, userid integer, created string, modified string, foreign key(userid) references users(userid));
create table endpoints (endpointid integer not null primary key, name string, path string, address string);
`)
if err != nil {