Add configuration files, database migrations, and authentication implementation scaffolding
This commit is contained in:
31
internal/db/sqlc/db.go
Normal file
31
internal/db/sqlc/db.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
29
internal/db/sqlc/models.go
Normal file
29
internal/db/sqlc/models.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type EncryptedLog struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
LogType string `json:"log_type"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
EncryptedPayload []byte `json:"encrypted_payload"`
|
||||
BlindIndexHash sql.NullString `json:"blind_index_hash"`
|
||||
ServerID string `json:"server_id"`
|
||||
SessionID sql.NullString `json:"session_id"`
|
||||
}
|
||||
|
||||
type Telemetry struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
CommunityID string `json:"community_id"`
|
||||
ServerFps float64 `json:"server_fps"`
|
||||
PlayerCount int32 `json:"player_count"`
|
||||
}
|
||||
17
internal/db/sqlc/querier.go
Normal file
17
internal/db/sqlc/querier.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
CreateEncryptedLog(ctx context.Context, arg CreateEncryptedLogParams) (EncryptedLog, error)
|
||||
CreateTelemetry(ctx context.Context, arg CreateTelemetryParams) (Telemetry, error)
|
||||
GetRecentLogs(ctx context.Context, arg GetRecentLogsParams) ([]EncryptedLog, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
||||
117
internal/db/sqlc/queries.sql.go
Normal file
117
internal/db/sqlc/queries.sql.go
Normal file
@@ -0,0 +1,117 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: queries.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const createEncryptedLog = `-- name: CreateEncryptedLog :one
|
||||
INSERT INTO encrypted_logs (
|
||||
log_type, encrypted_payload, blind_index_hash, server_id, session_id
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5
|
||||
) RETURNING id, log_type, created_at, encrypted_payload, blind_index_hash, server_id, session_id
|
||||
`
|
||||
|
||||
type CreateEncryptedLogParams struct {
|
||||
LogType string `json:"log_type"`
|
||||
EncryptedPayload []byte `json:"encrypted_payload"`
|
||||
BlindIndexHash sql.NullString `json:"blind_index_hash"`
|
||||
ServerID string `json:"server_id"`
|
||||
SessionID sql.NullString `json:"session_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateEncryptedLog(ctx context.Context, arg CreateEncryptedLogParams) (EncryptedLog, error) {
|
||||
row := q.db.QueryRowContext(ctx, createEncryptedLog,
|
||||
arg.LogType,
|
||||
arg.EncryptedPayload,
|
||||
arg.BlindIndexHash,
|
||||
arg.ServerID,
|
||||
arg.SessionID,
|
||||
)
|
||||
var i EncryptedLog
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.LogType,
|
||||
&i.CreatedAt,
|
||||
&i.EncryptedPayload,
|
||||
&i.BlindIndexHash,
|
||||
&i.ServerID,
|
||||
&i.SessionID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createTelemetry = `-- name: CreateTelemetry :one
|
||||
INSERT INTO telemetry (
|
||||
community_id, server_fps, player_count
|
||||
) VALUES (
|
||||
$1, $2, $3
|
||||
) RETURNING timestamp, community_id, server_fps, player_count
|
||||
`
|
||||
|
||||
type CreateTelemetryParams struct {
|
||||
CommunityID string `json:"community_id"`
|
||||
ServerFps float64 `json:"server_fps"`
|
||||
PlayerCount int32 `json:"player_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTelemetry(ctx context.Context, arg CreateTelemetryParams) (Telemetry, error) {
|
||||
row := q.db.QueryRowContext(ctx, createTelemetry, arg.CommunityID, arg.ServerFps, arg.PlayerCount)
|
||||
var i Telemetry
|
||||
err := row.Scan(
|
||||
&i.Timestamp,
|
||||
&i.CommunityID,
|
||||
&i.ServerFps,
|
||||
&i.PlayerCount,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getRecentLogs = `-- name: GetRecentLogs :many
|
||||
SELECT id, log_type, created_at, encrypted_payload, blind_index_hash, server_id, session_id FROM encrypted_logs
|
||||
WHERE server_id = $1
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type GetRecentLogsParams struct {
|
||||
ServerID string `json:"server_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetRecentLogs(ctx context.Context, arg GetRecentLogsParams) ([]EncryptedLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getRecentLogs, arg.ServerID, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EncryptedLog
|
||||
for rows.Next() {
|
||||
var i EncryptedLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.LogType,
|
||||
&i.CreatedAt,
|
||||
&i.EncryptedPayload,
|
||||
&i.BlindIndexHash,
|
||||
&i.ServerID,
|
||||
&i.SessionID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user