32 lines
450 B
Go
32 lines
450 B
Go
package main
|
|
|
|
import (
|
|
// Standard
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
type Session struct {
|
|
UUID string
|
|
UserID int
|
|
Created time.Time
|
|
}
|
|
|
|
func NewSession() (session Session, err error) {
|
|
var rows *sql.Rows
|
|
if rows, err = db.Query(`
|
|
INSERT INTO public.session(uuid)
|
|
VALUES(gen_random_uuid())
|
|
RETURNING uuid, created`,
|
|
); err != nil {
|
|
return
|
|
}
|
|
defer rows.Close()
|
|
|
|
if rows.Next() {
|
|
rows.Scan(&session.UUID, &session.Created)
|
|
}
|
|
|
|
return
|
|
}
|