feat: got sqlc to work

This commit is contained in:
2025-06-15 01:12:22 +03:00
parent db8b7c0372
commit 8aeb6e19d4
9 changed files with 130 additions and 3 deletions

View File

@@ -29,6 +29,9 @@ require (
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.5 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect

View File

@@ -55,6 +55,12 @@ github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeD
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=

View File

@@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
package database
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,57 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
package database
import (
"github.com/jackc/pgx/v5/pgtype"
)
type ConfirmationCode struct {
ID int64
UserID int64
Type int32
Code string
ExpiresAt pgtype.Timestamp
Used pgtype.Bool
Deleted pgtype.Bool
}
type LoginInformation struct {
ID int64
UserID int64
Email pgtype.Text
PasswordHash string
TotpEncrypted pgtype.Text
Email2faEnabled pgtype.Bool
PasswordChangeTime pgtype.Timestamp
}
type Profile struct {
ID int64
UserID int64
Name string
AvatarUrl pgtype.Text
Birthday pgtype.Timestamp
}
type Session struct {
ID int64
UserID int64
Guid string
Name pgtype.Text
Platform pgtype.Text
LatestIp pgtype.Text
LoginTime pgtype.Timestamp
LastSeenDate pgtype.Timestamp
Terminated pgtype.Bool
}
type User struct {
ID int64
Username string
Verified pgtype.Bool
Banned pgtype.Bool
RegistrationDate pgtype.Timestamp
}

View File

@@ -0,0 +1,27 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: query.sql
package database
import (
"context"
)
const createUser = `-- name: CreateUser :one
INSERT INTO users(username, verified, banned, registration_date) VALUES ($1, false, false, NOW()) RETURNING id, username, verified, banned, registration_date
`
func (q *Queries) CreateUser(ctx context.Context, username string) (User, error) {
row := q.db.QueryRow(ctx, createUser, username)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Verified,
&i.Banned,
&i.RegistrationDate,
)
return i, err
}

View File

@@ -38,6 +38,7 @@ services:
volumes:
- ./postgres_data:/var/lib/postgresql/data
- ./sqlc/schema.sql:/docker-entrypoint-initdb.d/init.sql
redis:
image: eqalpha/keydb
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"]

View File

@@ -1,2 +1,2 @@
-- name: CreateUser :one
INSERT INTO user (username, verified, banned, registration_date) VALUES ($1, false, false, NOW()) RETURNING id, username, verified, banned, registration_date;
INSERT INTO users(username, verified, banned, registration_date) VALUES ($1, false, false, NOW()) RETURNING id, username, verified, banned, registration_date;

View File

@@ -2,7 +2,8 @@
CREATE TABLE IF NOT EXISTS "users" (
id BIGSERIAL PRIMARY KEY,
username VARCHAR(20) UNIQUE NOT NULL,
banned BOOLEAN NOT NULL,
verified BOOLEAN,
banned BOOLEAN,
registration_date TIMESTAMP NOT NULL
);

View File

@@ -1,6 +1,6 @@
version: "2"
sql:
- schema: "../postgresql/schema.sql"
- schema: "schema.sql"
queries: "query.sql"
engine: "postgresql"
gen: