Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
efritz committed Sep 15, 2024
1 parent f400cd8 commit 86740e6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 43 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/go-nacelle/pgutil
go 1.21

require (
github.com/go-nacelle/config/v2 v2.0.1
github.com/go-nacelle/config/v3 v3.0.0
github.com/go-nacelle/log/v2 v2.0.1
github.com/go-nacelle/nacelle/v2 v2.1.1
github.com/google/go-cmp v0.6.0
Expand All @@ -22,7 +22,6 @@ require (
github.com/derision-test/glock v1.1.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-nacelle/config/v3 v3.0.0 // indirect
github.com/go-nacelle/process/v2 v2.1.0 // indirect
github.com/go-nacelle/service/v2 v2.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-nacelle/config/v2 v2.0.1 h1:/mBAe1xkaRYD+WFrG/DsOvlnj8bu8Ull33BWBQgS4ls=
github.com/go-nacelle/config/v2 v2.0.1/go.mod h1:NdcZcMmA2yqSjSZRNOD9tm3AifkrEYnmZKhjJjKMQB4=
github.com/go-nacelle/config/v3 v3.0.0 h1:YseTUtwKC21rgWNdBh+f0A5ANnh7kSMqGkB2JHI0aJ8=
github.com/go-nacelle/config/v3 v3.0.0/go.mod h1:cj+WGluCHOR/5gup6dx3wunXsEGEbxmCiB6cYa9iNYQ=
github.com/go-nacelle/log/v2 v2.0.1 h1:vOkiKz/pZannZIpH2yDV03hUKbtr6uLvrWklk8N6eR0=
Expand Down
4 changes: 2 additions & 2 deletions migration_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestUndo(t *testing.T) {
require.NoError(t, runner.ApplyAll(ctx))

// Assert columns exist and are populated
updatedAt, _, err := ScanNilTime(db.Query(ctx, RawQuery("SELECT created_at FROM comments WHERE user_id = 1")))
updatedAt, _, err := ScanNilTimestamp(db.Query(ctx, RawQuery("SELECT created_at FROM comments WHERE user_id = 1")))
require.NoError(t, err)
require.NotNil(t, updatedAt)

Expand All @@ -299,7 +299,7 @@ func TestUndo(t *testing.T) {
require.NoError(t, runnerWithHoles.Undo(ctx, 3))

// Assert created_at exists but updated_at does not
_, _, err = ScanNilTime(db.Query(ctx, RawQuery("SELECT created_at FROM comments WHERE user_id = 1")))
_, _, err = ScanNilTimestamp(db.Query(ctx, RawQuery("SELECT created_at FROM comments WHERE user_id = 1")))
require.NoError(t, err)
_, _, err = ScanString(db.Query(ctx, RawQuery("SELECT updated_at FROM comments WHERE user_id = 1")))
require.ErrorContains(t, err, "column \"updated_at\" does not exist")
Expand Down
99 changes: 62 additions & 37 deletions rows_slice_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,66 @@ func NewMaybeFirstScanner[T any](f MaybeScanValueFunc[T]) FirstScannerFunc[T] {
}

var (
ScanAny = NewFirstScanner(NewAnyValueScanner[any]())
ScanAnys = NewSliceScanner(NewAnyValueScanner[any]())
ScanBool = NewFirstScanner(NewAnyValueScanner[bool]())
ScanBools = NewSliceScanner(NewAnyValueScanner[bool]())
ScanFloat32 = NewFirstScanner(NewAnyValueScanner[float32]())
ScanFloat32s = NewSliceScanner(NewAnyValueScanner[float32]())
ScanFloat64 = NewFirstScanner(NewAnyValueScanner[float64]())
ScanFloat64s = NewSliceScanner(NewAnyValueScanner[float64]())
ScanInt = NewFirstScanner(NewAnyValueScanner[int]())
ScanInts = NewSliceScanner(NewAnyValueScanner[int]())
ScanInt16 = NewFirstScanner(NewAnyValueScanner[int16]())
ScanInt16s = NewSliceScanner(NewAnyValueScanner[int16]())
ScanInt32 = NewFirstScanner(NewAnyValueScanner[int32]())
ScanInt32s = NewSliceScanner(NewAnyValueScanner[int32]())
ScanInt64 = NewFirstScanner(NewAnyValueScanner[int64]())
ScanInt64s = NewSliceScanner(NewAnyValueScanner[int64]())
ScanInt8 = NewFirstScanner(NewAnyValueScanner[int8]())
ScanInt8s = NewSliceScanner(NewAnyValueScanner[int8]())
ScanString = NewFirstScanner(NewAnyValueScanner[string]())
ScanStrings = NewSliceScanner(NewAnyValueScanner[string]())
ScanUint = NewFirstScanner(NewAnyValueScanner[uint]())
ScanUints = NewSliceScanner(NewAnyValueScanner[uint]())
ScanUint16 = NewFirstScanner(NewAnyValueScanner[uint16]())
ScanUint16s = NewSliceScanner(NewAnyValueScanner[uint16]())
ScanUint32 = NewFirstScanner(NewAnyValueScanner[uint32]())
ScanUint32s = NewSliceScanner(NewAnyValueScanner[uint32]())
ScanUint64 = NewFirstScanner(NewAnyValueScanner[uint64]())
ScanUint64s = NewSliceScanner(NewAnyValueScanner[uint64]())
ScanUint8 = NewFirstScanner(NewAnyValueScanner[uint8]())
ScanUint8s = NewSliceScanner(NewAnyValueScanner[uint8]())

// TODO - nulls
// TODO - arrays
// TODO - bytes

ScanNilTime = NewFirstScanner(NewAnyValueScanner[*time.Time]())
ScanNilString = NewFirstScanner(NewAnyValueScanner[*string]())
ScanAny = NewFirstScanner(NewAnyValueScanner[any]())
ScanAnys = NewSliceScanner(NewAnyValueScanner[any]())
ScanBool = NewFirstScanner(NewAnyValueScanner[bool]())
ScanBools = NewSliceScanner(NewAnyValueScanner[bool]())
ScanFloat32 = NewFirstScanner(NewAnyValueScanner[float32]())
ScanFloat32s = NewSliceScanner(NewAnyValueScanner[float32]())
ScanFloat64 = NewFirstScanner(NewAnyValueScanner[float64]())
ScanFloat64s = NewSliceScanner(NewAnyValueScanner[float64]())
ScanInt = NewFirstScanner(NewAnyValueScanner[int]())
ScanInts = NewSliceScanner(NewAnyValueScanner[int]())
ScanInt16 = NewFirstScanner(NewAnyValueScanner[int16]())
ScanInt16s = NewSliceScanner(NewAnyValueScanner[int16]())
ScanInt32 = NewFirstScanner(NewAnyValueScanner[int32]())
ScanInt32s = NewSliceScanner(NewAnyValueScanner[int32]())
ScanInt64 = NewFirstScanner(NewAnyValueScanner[int64]())
ScanInt64s = NewSliceScanner(NewAnyValueScanner[int64]())
ScanInt8 = NewFirstScanner(NewAnyValueScanner[int8]())
ScanInt8s = NewSliceScanner(NewAnyValueScanner[int8]())
ScanString = NewFirstScanner(NewAnyValueScanner[string]())
ScanStrings = NewSliceScanner(NewAnyValueScanner[string]())
ScanUint = NewFirstScanner(NewAnyValueScanner[uint]())
ScanUints = NewSliceScanner(NewAnyValueScanner[uint]())
ScanUint16 = NewFirstScanner(NewAnyValueScanner[uint16]())
ScanUint16s = NewSliceScanner(NewAnyValueScanner[uint16]())
ScanUint32 = NewFirstScanner(NewAnyValueScanner[uint32]())
ScanUint32s = NewSliceScanner(NewAnyValueScanner[uint32]())
ScanUint64 = NewFirstScanner(NewAnyValueScanner[uint64]())
ScanUint64s = NewSliceScanner(NewAnyValueScanner[uint64]())
ScanUint8 = NewFirstScanner(NewAnyValueScanner[uint8]())
ScanUint8s = NewSliceScanner(NewAnyValueScanner[uint8]())
ScanTimestamp = NewFirstScanner(NewAnyValueScanner[time.Time]())
ScanTimestamps = NewSliceScanner(NewAnyValueScanner[time.Time]())
ScanNilBool = NewFirstScanner(NewAnyValueScanner[*bool]())
ScanNilBools = NewSliceScanner(NewAnyValueScanner[*bool]())
ScanNilFloat32 = NewFirstScanner(NewAnyValueScanner[*float32]())
ScanNilFloat32s = NewSliceScanner(NewAnyValueScanner[*float32]())
ScanNilFloat64 = NewFirstScanner(NewAnyValueScanner[*float64]())
ScanNilFloat64s = NewSliceScanner(NewAnyValueScanner[*float64]())
ScanNilInt = NewFirstScanner(NewAnyValueScanner[*int]())
ScanNilInts = NewSliceScanner(NewAnyValueScanner[*int]())
ScanNilInt16 = NewFirstScanner(NewAnyValueScanner[*int16]())
ScanNilInt16s = NewSliceScanner(NewAnyValueScanner[*int16]())
ScanNilInt32 = NewFirstScanner(NewAnyValueScanner[*int32]())
ScanNilInt32s = NewSliceScanner(NewAnyValueScanner[*int32]())
ScanNilInt64 = NewFirstScanner(NewAnyValueScanner[*int64]())
ScanNilInt64s = NewSliceScanner(NewAnyValueScanner[*int64]())
ScanNilInt8 = NewFirstScanner(NewAnyValueScanner[*int8]())
ScanNilInt8s = NewSliceScanner(NewAnyValueScanner[*int8]())
ScanNilString = NewFirstScanner(NewAnyValueScanner[*string]())
ScanNilStrings = NewSliceScanner(NewAnyValueScanner[*string]())
ScanNilUint = NewFirstScanner(NewAnyValueScanner[*uint]())
ScanNilUints = NewSliceScanner(NewAnyValueScanner[*uint]())
ScanNilUint16 = NewFirstScanner(NewAnyValueScanner[*uint16]())
ScanNilUint16s = NewSliceScanner(NewAnyValueScanner[*uint16]())
ScanNilUint32 = NewFirstScanner(NewAnyValueScanner[*uint32]())
ScanNilUint32s = NewSliceScanner(NewAnyValueScanner[*uint32]())
ScanNilUint64 = NewFirstScanner(NewAnyValueScanner[*uint64]())
ScanNilUint64s = NewSliceScanner(NewAnyValueScanner[*uint64]())
ScanNilUint8 = NewFirstScanner(NewAnyValueScanner[*uint8]())
ScanNilUint8s = NewSliceScanner(NewAnyValueScanner[*uint8]())
ScanNilTimestamp = NewFirstScanner(NewAnyValueScanner[*time.Time]())
ScanNilTimestamps = NewSliceScanner(NewAnyValueScanner[*time.Time]())
)

0 comments on commit 86740e6

Please sign in to comment.