Notes/session.go
2023-06-15 07:24:23 +02:00

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
}