mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 15:43:49 +01:00
An MMO server without multiplayer defeats the purpose. PostgreSQL is the right choice and Docker Compose already solves the setup pain. This reverts the common/db wrapper, SQLite schema, config Driver field, modernc.org/sqlite dependency, and all repo type changes while keeping the dashboard, wizard, and CI improvements from the previous commit.
30 lines
879 B
Go
30 lines
879 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
// APISessionRepository implements APISessionRepo with PostgreSQL.
|
|
type APISessionRepository struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
// NewAPISessionRepository creates a new APISessionRepository.
|
|
func NewAPISessionRepository(db *sqlx.DB) *APISessionRepository {
|
|
return &APISessionRepository{db: db}
|
|
}
|
|
|
|
func (r *APISessionRepository) CreateToken(ctx context.Context, uid uint32, token string) (uint32, error) {
|
|
var tid uint32
|
|
err := r.db.QueryRowContext(ctx, "INSERT INTO sign_sessions (user_id, token) VALUES ($1, $2) RETURNING id", uid, token).Scan(&tid)
|
|
return tid, err
|
|
}
|
|
|
|
func (r *APISessionRepository) GetUserIDByToken(ctx context.Context, token string) (uint32, error) {
|
|
var userID uint32
|
|
err := r.db.QueryRowContext(ctx, "SELECT user_id FROM sign_sessions WHERE token = $1", token).Scan(&userID)
|
|
return userID, err
|
|
}
|