File tree Expand file tree Collapse file tree 5 files changed +41
-0
lines changed Expand file tree Collapse file tree 5 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ require (
1919 github.com/stretchr/testify v1.10.0
2020 github.com/testcontainers/testcontainers-go/modules/mongodb v0.35.0
2121 github.com/uptrace/bun v1.2.11
22+ github.com/uptrace/bun/dbfixture v1.2.11
2223 github.com/uptrace/bun/dialect/pgdialect v1.2.11
2324 golang.org/x/crypto v0.33.0
2425)
Original file line number Diff line number Diff line change @@ -374,6 +374,8 @@ github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0o
374374github.com/uptrace/bun v0.3.9 /go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw =
375375github.com/uptrace/bun v1.2.11 h1:l9dTymsdZZAoSZ1+Qo3utms0RffgkDbIv+1UGk8N1wQ =
376376github.com/uptrace/bun v1.2.11 /go.mod h1:ww5G8h59UrOnCHmZ8O1I/4Djc7M/Z3E+EWFS2KLB6dQ =
377+ github.com/uptrace/bun/dbfixture v1.2.11 h1:9rKYVDwQCLdXtPkgzMgvDsHKHXelNlXmnpuNHvFz2w0 =
378+ github.com/uptrace/bun/dbfixture v1.2.11 /go.mod h1:E2H4A4/dx6+xB61qGsjVqV17Pqyb+Gg5QTmswy4hUpk =
377379github.com/uptrace/bun/dialect/pgdialect v1.2.11 h1:n0VKWm1fL1dwJK5TRxYYLaRKRe14BOg2+AQgpvqzG/M =
378380github.com/uptrace/bun/dialect/pgdialect v1.2.11 /go.mod h1:NvV1S/zwtwBnW8yhJ3XEKAQEw76SkeH7yUhfrx3W1Eo =
379381github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw =
Original file line number Diff line number Diff line change 1+ package options
2+
3+ import (
4+ "context"
5+ "io/fs"
6+ "os"
7+
8+ "github.com/uptrace/bun"
9+ "github.com/uptrace/bun/dbfixture"
10+ )
11+
12+ func WithFixtures (dir string ) Option {
13+ return func (ctx context.Context , db * bun.DB ) error {
14+ println ("path: " , dir )
15+
16+ fixture := dbfixture .New (db )
17+
18+ fsys := os .DirFS (dir )
19+ files , err := fs .ReadDir (fsys , "." )
20+ if err != nil {
21+ return err
22+ }
23+
24+ names := make ([]string , 0 )
25+ for _ , file := range files {
26+ println ("\t name: " , file .Name )
27+
28+ if ! file .IsDir () {
29+ names = append (names , file .Name ())
30+ }
31+ }
32+
33+ return fixture .Load (ctx , fsys , names ... )
34+ }
35+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ require (
3838 github.com/stretchr/objx v0.5.2 // indirect
3939 github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
4040 github.com/uptrace/bun v1.2.11 // indirect
41+ github.com/uptrace/bun/dbfixture v1.2.11 // indirect
4142 github.com/uptrace/bun/dialect/pgdialect v1.2.11 // indirect
4243 github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
4344 github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GH
113113github.com/uptrace/bun v0.3.9 /go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw =
114114github.com/uptrace/bun v1.2.11 h1:l9dTymsdZZAoSZ1+Qo3utms0RffgkDbIv+1UGk8N1wQ =
115115github.com/uptrace/bun v1.2.11 /go.mod h1:ww5G8h59UrOnCHmZ8O1I/4Djc7M/Z3E+EWFS2KLB6dQ =
116+ github.com/uptrace/bun/dbfixture v1.2.11 h1:9rKYVDwQCLdXtPkgzMgvDsHKHXelNlXmnpuNHvFz2w0 =
117+ github.com/uptrace/bun/dbfixture v1.2.11 /go.mod h1:E2H4A4/dx6+xB61qGsjVqV17Pqyb+Gg5QTmswy4hUpk =
116118github.com/uptrace/bun/dialect/pgdialect v1.2.11 h1:n0VKWm1fL1dwJK5TRxYYLaRKRe14BOg2+AQgpvqzG/M =
117119github.com/uptrace/bun/dialect/pgdialect v1.2.11 /go.mod h1:NvV1S/zwtwBnW8yhJ3XEKAQEw76SkeH7yUhfrx3W1Eo =
118120github.com/vmihailenco/msgpack/v5 v5.3.4 /go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc =
You can’t perform that action at this time.
0 commit comments