add user login sessions
This commit is contained in:
@@ -48,3 +48,9 @@ type User struct {
|
|||||||
LastLogin interface{}
|
LastLogin interface{}
|
||||||
CreatedAt sql.NullString
|
CreatedAt sql.NullString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserSession struct {
|
||||||
|
ID string
|
||||||
|
UserID string
|
||||||
|
CreatedAt string
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,6 +67,21 @@ func (q *Queries) CreateCustomer(ctx context.Context, arg CreateCustomerParams)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createNewSession = `-- name: CreateNewSession :exec
|
||||||
|
INSERT INTO user_sessions (id, user_id, created_at) VALUES (?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateNewSessionParams struct {
|
||||||
|
ID string
|
||||||
|
UserID string
|
||||||
|
CreatedAt string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateNewSession(ctx context.Context, arg CreateNewSessionParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createNewSession, arg.ID, arg.UserID, arg.CreatedAt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const createUser = `-- name: CreateUser :exec
|
const createUser = `-- name: CreateUser :exec
|
||||||
INSERT INTO user (
|
INSERT INTO user (
|
||||||
id
|
id
|
||||||
@@ -177,6 +192,17 @@ func (q *Queries) GetCustomer(ctx context.Context, id string) (GetCustomerRow, e
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getSession = `-- name: GetSession :one
|
||||||
|
SELECT id, user_id, created_at FROM user_sessions WHERE user_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetSession(ctx context.Context, userID string) (UserSession, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getSession, userID)
|
||||||
|
var i UserSession
|
||||||
|
err := row.Scan(&i.ID, &i.UserID, &i.CreatedAt)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const getSvgCount = `-- name: GetSvgCount :one
|
const getSvgCount = `-- name: GetSvgCount :one
|
||||||
SELECT COUNT(*) as count FROM svg_icon
|
SELECT COUNT(*) as count FROM svg_icon
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -87,6 +87,12 @@ SET
|
|||||||
,salt = ?
|
,salt = ?
|
||||||
WHERE id = ?;
|
WHERE id = ?;
|
||||||
|
|
||||||
|
-- name: CreateNewSession :exec
|
||||||
|
INSERT INTO user_sessions (id, user_id, created_at) VALUES (?, ?, ?);
|
||||||
|
|
||||||
|
-- name: GetSession :one
|
||||||
|
SELECT id, user_id, created_at FROM user_sessions WHERE user_id = ?;
|
||||||
|
|
||||||
-- name: GetUserRenew :many
|
-- name: GetUserRenew :many
|
||||||
SELECT
|
SELECT
|
||||||
id
|
id
|
||||||
|
|||||||
@@ -55,3 +55,11 @@ CREATE TABLE IF NOT EXISTS svg_icon (
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT
|
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
,svg TEXT NOT NULL
|
,svg TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS user_sessions (
|
||||||
|
id TEXT PRIMARY KEY
|
||||||
|
,user_id TEXT NOT NULL UNIQUE
|
||||||
|
,created_at TEXT NOT NULL
|
||||||
|
,FOREIGN KEY (user_id) REFERENCES user(id)
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user