Move database logic into separate subdirectory

I'm trying to see if this speeds up builds a bit. May not without a
module boundary, but for now it's nice organization to have as the
program grows.
This commit is contained in:
Eli Ribble 2025-11-24 18:08:24 +00:00
parent 338f90708e
commit 41587c3694
No known key found for this signature in database
333 changed files with 206 additions and 200 deletions

View file

@ -0,0 +1,76 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
"fmt"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/dialect/psql"
testutils "github.com/stephenafamo/bob/test/utils"
)
func TestUpdateOauthTokenOrg(t *testing.T) {
t.Run("Base", func(t *testing.T) {
var sb strings.Builder
query := UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil))
if _, err := query.WriteQuery(t.Context(), &sb, 1); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(updateOauthTokenOrgSQL, sb.String()); diff != "" {
t.Fatalf("unexpected result (-got +want):\n%s", diff)
}
})
t.Run("Mod", func(t *testing.T) {
var sb strings.Builder
query := UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil))
if _, err := psql.Update(query).WriteQuery(t.Context(), &sb, 1); err != nil {
t.Fatal(err)
}
queryDiff, err := testutils.QueryDiff(updateOauthTokenOrgSQL, sb.String(), formatQuery)
if err != nil {
t.Fatal(err)
}
if queryDiff != "" {
fmt.Println(sb.String())
t.Fatalf("unexpected result (-got +want):\n%s", queryDiff)
}
})
t.Run("Exec", func(t *testing.T) {
if testDB == nil {
t.Skip("skipping test, no DSN provided")
}
ctxTx, cancel := context.WithCancel(t.Context())
defer cancel()
tx, err := testDB.Begin(ctxTx)
if err != nil {
t.Fatalf("Error starting transaction: %v", err)
}
defer func() {
if err := tx.Rollback(ctxTx); err != nil {
t.Fatalf("Error rolling back transaction: %v", err)
}
}()
query := psql.Update(UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil)))
if _, err := bob.Exec(ctxTx, tx, query); err != nil {
t.Fatal(err)
}
})
}