81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
// versions:
|
||
|
// sqlc v1.20.0
|
||
|
// source: sessions.sql
|
||
|
|
||
|
package db
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const createSession = `-- name: CreateSession :one
|
||
|
INSERT INTO user_sessions (
|
||
|
username,
|
||
|
refresh_token,
|
||
|
user_agent,
|
||
|
client_ip,
|
||
|
is_blocked,
|
||
|
expires_at
|
||
|
) VALUES (
|
||
|
$1, $2, $3, $4, $5, $6
|
||
|
) RETURNING id, index_id, username, refresh_token, user_agent, client_ip, is_blocked, expires_at, created_at
|
||
|
`
|
||
|
|
||
|
type CreateSessionParams struct {
|
||
|
Username string `json:"username"`
|
||
|
RefreshToken string `json:"refresh_token"`
|
||
|
UserAgent string `json:"user_agent"`
|
||
|
ClientIp string `json:"client_ip"`
|
||
|
IsBlocked bool `json:"is_blocked"`
|
||
|
ExpiresAt time.Time `json:"expires_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (UserSession, error) {
|
||
|
row := q.db.QueryRowContext(ctx, createSession,
|
||
|
arg.Username,
|
||
|
arg.RefreshToken,
|
||
|
arg.UserAgent,
|
||
|
arg.ClientIp,
|
||
|
arg.IsBlocked,
|
||
|
arg.ExpiresAt,
|
||
|
)
|
||
|
var i UserSession
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.IndexID,
|
||
|
&i.Username,
|
||
|
&i.RefreshToken,
|
||
|
&i.UserAgent,
|
||
|
&i.ClientIp,
|
||
|
&i.IsBlocked,
|
||
|
&i.ExpiresAt,
|
||
|
&i.CreatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getSession = `-- name: GetSession :one
|
||
|
SELECT id, index_id, username, refresh_token, user_agent, client_ip, is_blocked, expires_at, created_at FROM user_sessions
|
||
|
WHERE id = $1
|
||
|
LIMIT 1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetSession(ctx context.Context, id int32) (UserSession, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getSession, id)
|
||
|
var i UserSession
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.IndexID,
|
||
|
&i.Username,
|
||
|
&i.RefreshToken,
|
||
|
&i.UserAgent,
|
||
|
&i.ClientIp,
|
||
|
&i.IsBlocked,
|
||
|
&i.ExpiresAt,
|
||
|
&i.CreatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|