pico
created pr with
97.1
added 97.2
1: fdc255e = 1: fdc255e refactor: remove unused db methods
2: 3f855f6 = 2: 3f855f6 chore: add tests for postgres db impl
3: 7cd29a6 = 3: 7cd29a6 refactor: use sqlx interface
4: acd449e = 4: acd449e chore: add db tags
5: f6ed0d7 = 5: f6ed0d7 refactor: use sqlx
6: 29035c6 = 6: 29035c6 refactor: replace custom sql functions with sqlx
7: d4ea6d9 = 7: d4ea6d9 refactor: inline all sql queries
-: ------- > 8: 4bd37ed refactor: use `select * from` where possible
cmds
checkout latest patchset:
ssh pr.pico.sh print 97 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 97.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 97
Patchset
97.2
refactor: remove unused db methods
Eric Bower
chore: add tests for postgres db impl
2025-12-18T03:03:10ZEric Bower
→ refactor: use sqlx interface
2025-12-18T03:17:57ZEric Bower
chore: add db tags
2025-12-18T03:27:57ZEric Bower
refactor: use sqlx
2025-12-18T03:31:25ZEric Bower
refactor: replace custom sql functions with sqlx
2025-12-18T03:43:01ZEric Bower
refactor: inline all sql queries
2025-12-18T03:57:00ZEric Bower
refactor: use `select * from` where possible
2025-12-18T04:02:50ZEric Bower
2025-12-18T04:33:58Z
refactor: use sqlx interface
Eric Bower
2025-12-18T03:27:57ZSemantic diff summary
0 added,
6 modified,
4 signature changed,
0 removed
across 5 analyzed files
+2
-1
cmd/scripts/dates/dates.go
#
| ... | ... | @@ -7,12 +7,13 @@ import ( | |
| 7 | 7 | "os" | |
| 8 | 8 | "time" | |
| 9 | 9 | ||
| 10 | + | "github.com/jmoiron/sqlx" | |
| 10 | 11 | "github.com/picosh/pico/pkg/db" | |
| 11 | 12 | "github.com/picosh/pico/pkg/db/postgres" | |
| 12 | 13 | "github.com/picosh/pico/pkg/shared" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| 15 | - | func findPosts(dbpool *sql.DB) ([]*db.Post, error) { | |
| 16 | + | func findPosts(dbpool *sqlx.DB) ([]*db.Post, error) { | |
| 16 | 17 | var posts []*db.Post | |
| 17 | 18 | rs, err := dbpool.Query(`SELECT | |
| 18 | 19 | id, user_id, filename, title, text, description, |
+2
-1
cmd/scripts/migrate/migrate.go
#
| ... | ... | @@ -7,12 +7,13 @@ import ( | |
| 7 | 7 | "log/slog" | |
| 8 | 8 | "os" | |
| 9 | 9 | ||
| 10 | + | "github.com/jmoiron/sqlx" | |
| 10 | 11 | "github.com/picosh/pico/pkg/db" | |
| 11 | 12 | "github.com/picosh/pico/pkg/db/postgres" | |
| 12 | 13 | "github.com/picosh/pico/pkg/shared" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| 15 | - | func findPosts(dbpool *sql.DB) ([]*db.Post, error) { | |
| 16 | + | func findPosts(dbpool *sqlx.DB) ([]*db.Post, error) { | |
| 16 | 17 | var posts []*db.Post | |
| 17 | 18 | rs, err := dbpool.Query(`SELECT | |
| 18 | 19 | posts.id, user_id, filename, title, text, description, |
+2
-2
cmd/scripts/tags/tags.go
#
| ... | ... | @@ -1,16 +1,16 @@ | |
| 1 | 1 | package main | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "database/sql" | |
| 5 | 4 | "log/slog" | |
| 6 | 5 | "os" | |
| 7 | 6 | ||
| 7 | + | "github.com/jmoiron/sqlx" | |
| 8 | 8 | "github.com/picosh/pico/pkg/db" | |
| 9 | 9 | "github.com/picosh/pico/pkg/db/postgres" | |
| 10 | 10 | "github.com/picosh/pico/pkg/shared" | |
| 11 | 11 | ) | |
| 12 | 12 | ||
| 13 | - | func findPosts(dbpool *sql.DB) ([]*db.Post, error) { | |
| 13 | + | func findPosts(dbpool *sqlx.DB) ([]*db.Post, error) { | |
| 14 | 14 | var posts []*db.Post | |
| 15 | 15 | rs, err := dbpool.Query(`SELECT | |
| 16 | 16 | posts.id, user_id, filename, title, text, description, |
+3
-2
pkg/db/postgres/storage.go
#
| ... | ... | @@ -297,7 +298,7 @@ func NewDB(databaseUrl string, logger *slog.Logger) *PsqlDB { | |
| 297 | 298 | } | |
| 298 | 299 | d.Logger.Info("Connecting to postgres", "databaseUrl", databaseUrl) | |
| 299 | 300 | ||
| 300 | - | db, err := sql.Open("postgres", databaseUrl) | |
| 301 | + | db, err := sqlx.Connect("postgres", databaseUrl) | |
| 301 | 302 | if err != nil { | |
| 302 | 303 | d.Logger.Error(err.Error()) | |
| 303 | 304 | } |
+4
-4
pkg/db/postgres/storage_test.go
#
| ... | ... | @@ -34,14 +34,14 @@ func setupContainerRuntime() bool { | |
| 34 | 34 | if cmd := exec.Command("podman", "info"); cmd.Run() == nil { | |
| 35 | 35 | // For podman, we need to ensure the socket is running | |
| 36 | 36 | // User should run: systemctl --user start podman.socket | |
| 37 | - | os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true") | |
| 37 | + | _ = os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true") | |
| 38 | 38 | ||
| 39 | 39 | // Check if socket exists and is accessible | |
| 40 | 40 | xdgRuntime := os.Getenv("XDG_RUNTIME_DIR") | |
| 41 | 41 | if xdgRuntime != "" { | |
| 42 | 42 | socketPath := xdgRuntime + "/podman/podman.sock" | |
| 43 | 43 | if _, err := os.Stat(socketPath); err == nil { | |
| 44 | - | os.Setenv("DOCKER_HOST", "unix://"+socketPath) | |
| 44 | + | _ = os.Setenv("DOCKER_HOST", "unix://"+socketPath) | |
| 45 | 45 | return true | |
| 46 | 46 | } | |
| 47 | 47 | } |
| ... | ... | @@ -127,7 +127,7 @@ func getProjectRoot() string { | |
| 127 | 127 | return filepath.Join(filepath.Dir(filename), "..", "..", "..") | |
| 128 | 128 | } | |
| 129 | 129 | ||
| 130 | - | func setupTestSchema(db *sql.DB) error { | |
| 130 | + | func setupTestSchema(db *sqlx.DB) error { | |
| 131 | 131 | projectRoot := getProjectRoot() | |
| 132 | 132 | migrationsDir := filepath.Join(projectRoot, "sql", "migrations") | |
| 133 | 133 |