feat: better types overriding

This commit is contained in:
2025-06-04 12:32:47 +02:00
parent 243b7cce33
commit 92e9b87227
4 changed files with 126 additions and 43 deletions

View File

@ -9,7 +9,6 @@ import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
) )
const activateApiService = `-- name: ActivateApiService :exec const activateApiService = `-- name: ActivateApiService :exec
@ -36,7 +35,7 @@ type CreateApiServiceParams struct {
ClientID string `json:"client_id"` ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"` ClientSecret string `json:"client_secret"`
Name string `json:"name"` Name string `json:"name"`
Description pgtype.Text `json:"description"` Description *string `json:"description"`
RedirectUris []string `json:"redirect_uris"` RedirectUris []string `json:"redirect_uris"`
Scopes []string `json:"scopes"` Scopes []string `json:"scopes"`
GrantTypes []string `json:"grant_types"` GrantTypes []string `json:"grant_types"`
@ -187,7 +186,7 @@ RETURNING id, client_id, client_secret, name, redirect_uris, scopes, grant_types
type UpdateApiServiceParams struct { type UpdateApiServiceParams struct {
ClientID string `json:"client_id"` ClientID string `json:"client_id"`
Name string `json:"name"` Name string `json:"name"`
Description pgtype.Text `json:"description"` Description *string `json:"description"`
RedirectUris []string `json:"redirect_uris"` RedirectUris []string `json:"redirect_uris"`
Scopes []string `json:"scopes"` Scopes []string `json:"scopes"`
GrantTypes []string `json:"grant_types"` GrantTypes []string `json:"grant_types"`

View File

@ -8,7 +8,6 @@ import (
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
) )
type ApiService struct { type ApiService struct {
@ -22,7 +21,7 @@ type ApiService struct {
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
IsActive bool `json:"is_active"` IsActive bool `json:"is_active"`
Description pgtype.Text `json:"description"` Description *string `json:"description"`
} }
type User struct { type User struct {
@ -31,9 +30,9 @@ type User struct {
FullName string `json:"full_name"` FullName string `json:"full_name"`
PasswordHash string `json:"password_hash"` PasswordHash string `json:"password_hash"`
IsAdmin bool `json:"is_admin"` IsAdmin bool `json:"is_admin"`
CreatedAt pgtype.Timestamptz `json:"created_at"` CreatedAt *time.Time `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"` UpdatedAt *time.Time `json:"updated_at"`
LastLogin pgtype.Timestamptz `json:"last_login"` LastLogin *time.Time `json:"last_login"`
PhoneNumber pgtype.Text `json:"phone_number"` PhoneNumber *string `json:"phone_number"`
ProfilePicture pgtype.Text `json:"profile_picture"` ProfilePicture *string `json:"profile_picture"`
} }

View File

@ -9,7 +9,6 @@ import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
) )
const findAllUsers = `-- name: FindAllUsers :many const findAllUsers = `-- name: FindAllUsers :many
@ -126,7 +125,7 @@ WHERE id = $2
` `
type UpdateProfilePictureParams struct { type UpdateProfilePictureParams struct {
ProfilePicture pgtype.Text `json:"profile_picture"` ProfilePicture *string `json:"profile_picture"`
ID uuid.UUID `json:"id"` ID uuid.UUID `json:"id"`
} }

View File

@ -1,4 +1,3 @@
version: "2" version: "2"
sql: sql:
- engine: "postgresql" - engine: "postgresql"
@ -14,8 +13,95 @@ sql:
- db_type: "uuid" - db_type: "uuid"
go_type: go_type:
import: "github.com/google/uuid" import: "github.com/google/uuid"
type: "UUID" type: UUID
- db_type: "timestamptz" - db_type: "uuid"
nullable: true
go_type:
import: "github.com/google/uuid"
type: UUID
pointer: true
# ───── bool ──────────────────────────────────────────
- db_type: "pg_catalog.bool" # or just "bool"
go_type: { type: "bool" }
- db_type: "bool" # or just "bool"
go_type: { type: "bool" }
- db_type: "pg_catalog.bool"
nullable: true
go_type:
type: "bool"
pointer: true # ⇒ *bool for NULLable columns
- db_type: "bool"
nullable: true
go_type:
type: "bool"
pointer: true # ⇒ *bool for NULLable columns
# ───── text ──────────────────────────────────────────
- db_type: "pg_catalog.text"
go_type: { type: "string" }
- db_type: "text" # or just "bool"
go_type: { type: "string" }
- db_type: "pg_catalog.text"
nullable: true
go_type:
type: "string"
pointer: true # ⇒ *bool for NULLable columns
- db_type: "text"
nullable: true
go_type:
type: "string"
pointer: true # ⇒ *bool for NULLable columns
# ───── timestamp (WITHOUT TZ) ────────────────────────
- db_type: "pg_catalog.timestamp" # or "timestamp"
go_type: go_type:
import: "time" import: "time"
type: "Time" type: "Time"
- db_type: "timestamp" # or "timestamp"
go_type:
import: "time"
type: "Time"
- db_type: "pg_catalog.timestamp"
nullable: true
go_type:
import: "time"
type: "Time"
pointer: true
- db_type: "timestamp"
nullable: true
go_type:
import: "time"
type: "Time"
pointer: true
# ───── timestamptz (WITH TZ) ─────────────────────────
- db_type: "pg_catalog.timestamptz" # or "timestamptz"
go_type:
import: "time"
type: "Time"
- db_type: "timestamptz" # or "timestamptz"
go_type:
import: "time"
type: "Time"
- db_type: "pg_catalog.timestamptz"
nullable: true
go_type:
import: "time"
type: "Time"
pointer: true
- db_type: "timestamptz"
nullable: true
go_type:
import: "time"
type: "Time"
pointer: true