summaryrefslogtreecommitdiff
path: root/services/worker/internal/database
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-07 01:42:57 -0800
committerFuwn <[email protected]>2026-02-07 01:42:57 -0800
commit5c5b1993edd890a80870ee05607ac5f088191d4e (patch)
treea721b76bcd49ba10826c53efc87302c7a689512f /services/worker/internal/database
downloadasa.news-5c5b1993edd890a80870ee05607ac5f088191d4e.tar.xz
asa.news-5c5b1993edd890a80870ee05607ac5f088191d4e.zip
feat: asa.news RSS reader with developer tier, REST API, and webhooks
Full-stack RSS reader SaaS: Supabase + Next.js + Go worker. Includes three subscription tiers (free/pro/developer), API key auth, read-only REST API, webhook push notifications, Stripe billing with proration, and PWA support.
Diffstat (limited to 'services/worker/internal/database')
-rw-r--r--services/worker/internal/database/database.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/services/worker/internal/database/database.go b/services/worker/internal/database/database.go
new file mode 100644
index 0000000..2b2900f
--- /dev/null
+++ b/services/worker/internal/database/database.go
@@ -0,0 +1,39 @@
+package database
+
+import (
+ "context"
+ "fmt"
+ "github.com/jackc/pgx/v5"
+ "github.com/jackc/pgx/v5/pgxpool"
+ "time"
+)
+
+func CreateConnectionPool(parentContext context.Context, databaseURL string) (*pgxpool.Pool, error) {
+ poolConfiguration, parseError := pgxpool.ParseConfig(databaseURL)
+
+ if parseError != nil {
+ return nil, fmt.Errorf("failed to parse database URL: %w", parseError)
+ }
+
+ poolConfiguration.MaxConns = 25
+ poolConfiguration.MinConns = 5
+ poolConfiguration.MaxConnLifetime = 30 * time.Minute
+ poolConfiguration.MaxConnIdleTime = 5 * time.Minute
+ poolConfiguration.HealthCheckPeriod = 30 * time.Second
+ poolConfiguration.ConnConfig.DefaultQueryExecMode = pgx.QueryExecModeExec
+ connectionPool, connectionError := pgxpool.NewWithConfig(parentContext, poolConfiguration)
+
+ if connectionError != nil {
+ return nil, fmt.Errorf("failed to create connection pool: %w", connectionError)
+ }
+
+ pingError := connectionPool.Ping(parentContext)
+
+ if pingError != nil {
+ connectionPool.Close()
+
+ return nil, fmt.Errorf("failed to ping database: %w", pingError)
+ }
+
+ return connectionPool, nil
+}