diff --git a/sample/data/base/comments.dbf.yaml b/sample/data/base/comments.dbf.yaml deleted file mode 100644 index d23f210..0000000 --- a/sample/data/base/comments.dbf.yaml +++ /dev/null @@ -1,17 +0,0 @@ -comments: - config: - depends: - - posts - rows: - - comment_id: 1 - post_id: 1 - user_id: !dbfexpr "refid:users:janedoe:user_id" - text: "Good post!" - created_at: !!timestamp 2023-01-01T12:31:12Z - updated_at: !!timestamp 2023-01-01T12:31:12Z - - comment_id: 2 - post_id: 1 - user_id: !dbfexpr "refid:users:johndoe:user_id" - text: "Thanks!" - created_at: !!timestamp 2023-01-01T12:35:12Z - updated_at: !!timestamp 2023-01-01T12:35:12Z diff --git a/sample/data/base/posts.dbf.yaml b/sample/data/base/posts.dbf.yaml deleted file mode 100644 index b9d89fc..0000000 --- a/sample/data/base/posts.dbf.yaml +++ /dev/null @@ -1,36 +0,0 @@ -posts: - config: - table_name: "post" - rows: - - post_id: 1 - title: "Post 1" - text: "This is the text of the first post" - user_id: !dbfexpr "refid:users:johndoe:user_id" - created_at: !!timestamp 2023-01-01T12:30:12Z - updated_at: !!timestamp 2023-01-01T12:30:12Z - _dbfdeps: - posts_tags: - rows: - - post_id: !dbfexpr "parent:post_id" - tag_id: !dbfexpr "refid:tags:go:tag_id" - _dbfconfig: - refid: "post_1" - tags: ["initial"] - - post_id: 2 - parent_post_id: !dbfexpr "refid:posts:post_1:post_id" - title: "Post 2" - text: "This is the text of the seco d post" - user_id: !dbfexpr "refid:users:johndoe:user_id" - created_at: !!timestamp 2023-01-02T12:30:12Z - updated_at: !!timestamp 2023-01-02T12:30:12Z - _dbfdeps: - posts_tags: - rows: - - post_id: !dbfexpr "parent:post_id" - tag_id: !dbfexpr "refid:tags:javascript:tag_id" - comments: - rows: - - comment_id: 3 - post_id: !dbfexpr "parent:post_id" - user_id: !dbfexpr "refid:users:janedoe:user_id" - text: "I liked this post!" diff --git a/sample/data/base/posts_tags.dbf.yaml b/sample/data/base/posts_tags.dbf.yaml deleted file mode 100644 index 38839b1..0000000 --- a/sample/data/base/posts_tags.dbf.yaml +++ /dev/null @@ -1,3 +0,0 @@ -posts_tags: - config: - table_name: "post_tag" diff --git a/sample/data/base/tags.dbf.yaml b/sample/data/base/tags.dbf.yaml deleted file mode 100644 index 350e898..0000000 --- a/sample/data/base/tags.dbf.yaml +++ /dev/null @@ -1,22 +0,0 @@ -tags: - config: - table_name: "tag" - rows: - - tag_id: !dbfexpr "generated" - name: "Go" - created_at: !!timestamp 2023-01-01T12:30:12Z - updated_at: !!timestamp 2023-01-01T12:30:12Z - _dbfconfig: - refid: "go" - - tag_id: !dbfexpr "generated" - name: "JavaScript" - created_at: !!timestamp 2023-01-01T12:30:12Z - updated_at: !!timestamp 2023-01-01T12:30:12Z - _dbfconfig: - refid: "javascript" - - tag_id: !dbfexpr "generated" - name: "C++" - created_at: !!timestamp 2023-01-01T12:30:12Z - updated_at: !!timestamp 2023-01-01T12:30:12Z - _dbfconfig: - refid: "cpp" diff --git a/sample/data/base/users.dbf.yaml b/sample/data/base/users.dbf.yaml deleted file mode 100644 index f3258f0..0000000 --- a/sample/data/base/users.dbf.yaml +++ /dev/null @@ -1,20 +0,0 @@ -users: - config: - table_name: "user" - rows: - - user_id: 1 - name: "John Doe" - email: "john@example.com" - created_at: !!timestamp 2023-01-01T12:30:12Z - updated_at: !!timestamp 2023-01-01T12:30:12Z - _dbfconfig: - refid: "johndoe" - - user_id: 2 - name: "Jane Doe" - email: "jane@example.com" - created_at: !!timestamp 2023-01-04T12:30:12Z - updated_at: !!timestamp 2023-01-04T12:30:12Z - _dbfconfig: - refid: "janedoe" - tags: - - onlyone diff --git a/sample/data/test1/posts_test1.dbf.yaml b/sample/data/test1/posts_test1.dbf.yaml deleted file mode 100644 index 5380bcc..0000000 --- a/sample/data/test1/posts_test1.dbf.yaml +++ /dev/null @@ -1,13 +0,0 @@ -posts: - rows: - - post_id: 5 - title: "Post 5" - text: "This is the text of the fifth post" - user_id: !dbfexpr "refid:users:janedoe:user_id" - created_at: !!timestamp 2023-01-05T12:30:12Z - updated_at: !!timestamp 2023-01-05T12:30:12Z - _dbfdeps: - posts_tags: - rows: - - post_id: !dbfexpr "parent:post_id" - tag_id: !dbfexpr "refid:tags:javascript:tag_id" diff --git a/sample/go.mod b/sample/go.mod deleted file mode 100644 index d8746ea..0000000 --- a/sample/go.mod +++ /dev/null @@ -1,20 +0,0 @@ -module github.com/rrgmc/debefix/sample - -go 1.21.1 - -require ( - github.com/rrgmc/debefix v0.0.0 - github.com/davecgh/go-spew v1.1.1 - github.com/google/uuid v1.3.1 -) - -require ( - github.com/fatih/color v1.10.0 // indirect - github.com/goccy/go-yaml v1.11.2 // indirect - github.com/mattn/go-colorable v0.1.8 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect -) - -replace github.com/rrgmc/debefix v0.0.0 => ../ diff --git a/sample/go.sum b/sample/go.sum deleted file mode 100644 index c3e83f0..0000000 --- a/sample/go.sum +++ /dev/null @@ -1,30 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/goccy/go-yaml v1.11.2 h1:joq77SxuyIs9zzxEjgyLBugMQ9NEgTWxXfz2wVqwAaQ= -github.com/goccy/go-yaml v1.11.2/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/sample/sample.go b/sample/sample.go deleted file mode 100644 index b5c09e3..0000000 --- a/sample/sample.go +++ /dev/null @@ -1,86 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "path/filepath" - "runtime" - "strings" - - "github.com/davecgh/go-spew/spew" - "github.com/google/uuid" - "github.com/rrgmc/debefix" - "github.com/rrgmc/debefix/db/sql" - "github.com/rrgmc/debefix/db/sql/postgres" -) - -func currentSourceDirectory() (string, error) { - _, filename, _, ok := runtime.Caller(0) - if !ok { - return "", errors.New("unable to get the current filename") - } - return filepath.Dir(filename), nil -} - -func main() { - curDir, err := currentSourceDirectory() - if err != nil { - panic(err) - } - - data, err := debefix.Load(debefix.NewDirectoryFileProvider(filepath.Join(curDir, "data"), - debefix.WithDirectoryAsTag())) - if err != nil { - panic(err) - } - - // spew.Dump(data) - - resolveTags := []string{} - - err = debefix.ResolveCheck(data, debefix.WithResolveTags(resolveTags)) - if err != nil { - panic(err) - } - - // err = resolvePrint(data, resolveTags) - // if err != nil { - // panic(err) - // } - - err = resolveSQL(data, resolveTags) - if err != nil { - panic(err) - } -} - -func resolvePrint(data *debefix.Data, resolveTags []string) error { - _, err := debefix.Resolve(data, func(ctx debefix.ResolveContext, fields map[string]any) error { - fmt.Printf("%s %s %s\n", strings.Repeat("=", 10), ctx.TableName(), strings.Repeat("=", 10)) - spew.Dump(fields) - - resolved := map[string]any{} - for fn, fv := range fields { - if fresolve, ok := fv.(debefix.ResolveValue); ok { - switch fresolve.(type) { - case *debefix.ResolveGenerate: - ctx.ResolveField(fn, uuid.New()) - resolved[fn] = uuid.New() - } - } - } - - if len(resolved) > 0 { - fmt.Println("---") - spew.Dump(resolved) - } - - return nil - }, debefix.WithResolveTags(resolveTags)) - return err -} - -func resolveSQL(data *debefix.Data, resolveTags []string) error { - _, err := postgres.Resolve(sql.NewDebugQueryInterface(nil), data, debefix.WithResolveTags(resolveTags)) - return err -}