feat: got sqlc to work

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

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: