aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2018-12-28 12:04:28 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2018-12-28 12:04:28 -0500
commit04cf96cdc3ef6c78b2d4754e3c8028b5c1c45fc0 (patch)
tree527cf6b90b4e90382c6f95049e580616e1b9932e
parentb8b80e0a896433bed8eb331aff3ecd12e00fd4ba (diff)
downloadid-04cf96cdc3ef6c78b2d4754e3c8028b5c1c45fc0.tar.gz
update schema
-rw-r--r--schema.sql12
-rw-r--r--store.go10
2 files changed, 12 insertions, 10 deletions
diff --git a/schema.sql b/schema.sql
index a2a74b1..5fd2c3e 100644
--- a/schema.sql
+++ b/schema.sql
@@ -1,10 +1,12 @@
+CREATE TABLE users(
+ id serial PRIMARY KEY,
+ name text,
+ password text);
+
CREATE TABLE sessions(
+ id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
created_at timestamp DEFAULT now(),
- session_id uuid DEFAULT gen_random_uuid(),
+ expire timestamp,
user_id integer REFERENCES users(id)
);
-CREATE TABLE users(
- id integer PRIMARY KEY serial,
- user_name text
- password text);
diff --git a/store.go b/store.go
index 9a28840..1f0ca76 100644
--- a/store.go
+++ b/store.go
@@ -14,7 +14,7 @@ type Session struct {
type User struct {
Id int64
- UserName string
+ Name string
Password []byte
}
@@ -43,7 +43,7 @@ func (store *PgStore) GetSession(id string) (*Session, bool) {
}
s = new(Session)
row := store.QueryRow("SELECT id, user_id FROM session WHERE id = $1", id)
- if err := row.Scan(s.Id, s.UserId); err != nil {
+ if err := row.Scan(&s.Id, &s.UserId); err != nil {
return nil, false
}
store.sessionCache[s.Id] = s
@@ -51,9 +51,9 @@ func (store *PgStore) GetSession(id string) (*Session, bool) {
}
func (store *PgStore) GetUser(name string) (*User, bool) {
- u := new(User)
- row := store.QueryRow("SELECT id, user_name, password FROM user WHERE user_name = $1", name)
- if err := row.Scan(u.Id, u.UserName, u.Password); err != nil {
+ u := &User{Name: name}
+ row := store.QueryRow("SELECT id, password FROM user WHERE name = $1", name)
+ if err := row.Scan(&u.Id, &u.Password); err != nil {
return nil, false
}
return u, true