Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sqlc setup #455

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Add sqlc setup #455

wants to merge 4 commits into from

Conversation

jakubno
Copy link
Member

@jakubno jakubno commented Mar 14, 2025

Description

Minimal configuration for sqlc, the idea is to start minimal and progressively convert to sqlc.

This way we will have time to properly evaluate without huge investment on refactoring whole codebase. Also the style we want to use it will probably evolve.

Also started separating shared and db packages

@jakubno jakubno added improvement Improvement for current functionality go Pull requests that update go code labels Mar 14, 2025
@jakubno jakubno self-assigned this Mar 14, 2025
conn *pgxpool.Pool
}

var databaseURL = os.Getenv("POSTGRES_CONNECTION_STRING")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to load the env vars here via the utils.RequiredEnv?

// Parse the connection pool configuration
config, err := pgxpool.ParseConfig(databaseURL)
if err != nil {
log.Fatalf("Unable to parse database URL: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to do log.Fatal here that does os.Exit vs returning error so we can handle that (also by quitting probably).

// Create the connection pool
pool, err := pgxpool.NewWithConfig(ctx, config)
if err != nil {
log.Fatalf("Unable to create connection pool: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment above about returning error.

@@ -0,0 +1,3 @@
-- name: Example :one
SELECT *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the example here intentional?

if err != nil {
log.Fatalf("Unable to create connection pool: %v", err)
}
defer pool.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the pool closed on defer, before we return the client?

@jakubno jakubno marked this pull request as draft March 15, 2025 21:16
@jakubno
Copy link
Member Author

jakubno commented Mar 15, 2025

It isn't ready yet, sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update go code improvement Improvement for current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants