Skip to content

Instantly share code, notes, and snippets.

@mlaflamm
Last active September 12, 2023 20:22
Show Gist options
  • Save mlaflamm/5093c5877b401f608a1a737fab7b662c to your computer and use it in GitHub Desktop.
Save mlaflamm/5093c5877b401f608a1a737fab7b662c to your computer and use it in GitHub Desktop.

Revisions

  1. mlaflamm revised this gist Apr 21, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions jet.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    # 'rm' and 'mv' are for flattening the deep directory structure
    rm -rf jetdb model table
    go run github.com/go-jet/jet/v2/cmd/jet -source=PostgreSQL -host=localhost -port=5432 -user=jetuser -password=jetpass -dbname=jetdb -schema=dvds -path=.
    jet -source=PostgreSQL -host=localhost -port=5432 -user=jetuser -password=jetpass -dbname=jetdb -schema=dvds -path=.
    mv ./jetdb/dvds/* .
    rm -rf jetdb

    @@ -32,4 +32,4 @@ else
    fi

    # this is to remove unused import packages
    find ./model -type f -name '*.go' | xargs go run golang.org/x/tools/cmd/goimports -w
    find ./model -type f -name '*.go' | xargs goimports -w
  2. mlaflamm revised this gist Nov 23, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions jet.sh
    Original file line number Diff line number Diff line change
    @@ -13,12 +13,16 @@ rm */schema_migrations.go
    if [ "$(uname)" == "Darwin" ]; then
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|int32|int|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*int|null.Int|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*float64|null.String|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|float64|string|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*string|null.String|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*time.Time|null.Time|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|package model|package model\'$'\nimport "github.com/volatiletech/null/v8"|g'
    elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
    find ./model -type f -name '*.go' | xargs sed -i 's|int32|int|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|*int|null.Int|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|*float64|null.String|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|float64|string|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|*string|null.String|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|*time.Time|null.Time|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|package model|package model\n\nimport "github.com/volatiletech/null/v8"|g'
  3. mlaflamm revised this gist Nov 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jet.sh
    Original file line number Diff line number Diff line change
    @@ -27,5 +27,5 @@ else
    exit 1
    fi

    # this is to removes unused import packages
    # this is to remove unused import packages
    find ./model -type f -name '*.go' | xargs go run golang.org/x/tools/cmd/goimports -w
  4. mlaflamm revised this gist Nov 21, 2020. 2 changed files with 4 additions and 3 deletions.
    5 changes: 3 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,10 @@ Yes this is possible to revert to raw SQL but then we lose some of the type safe

    When we discovered `go-jet`, we were very excited.
    A type safe SQL builder solution with code generation is exactly what we were looking for!
    Our only complaint was the usage of pointers for nullable values instead of the convenient `null` types.
    Our only gripe was the usage of pointers for nullable values instead of the convenient `null` types.
    You can use different types if you provide you own custom models but we really wants to use the generated models.

    After tinkering with multiple ways to generate `go-jet` models with `null` types, we ended up wrapping the jet code generator with a bash script
    that automatically converts the types of the `go-jet` models to our beloved `null` types.

    Here it is in its full glory.
    Here is the bash wrapper in its full glory.
    2 changes: 1 addition & 1 deletion jet.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash

    # 'rm' and 'mv' are for flattening the annoyingly deep directory structure
    # 'rm' and 'mv' are for flattening the deep directory structure
    rm -rf jetdb model table
    go run github.com/go-jet/jet/v2/cmd/jet -source=PostgreSQL -host=localhost -port=5432 -user=jetuser -password=jetpass -dbname=jetdb -schema=dvds -path=.
    mv ./jetdb/dvds/* .
  5. mlaflamm revised this gist Nov 16, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,6 @@ A type safe SQL builder solution with code generation is exactly what we were lo
    Our only complaint was the usage of pointers for nullable values instead of the convenient `null` types.

    After tinkering with multiple ways to generate `go-jet` models with `null` types, we ended up wrapping the jet code generator with a bash script
    that automatically converts the types of the `go-jet` models to our beloved `null` types.
    that automatically converts the types of the `go-jet` models to our beloved `null` types.

    Here it is in its full glory.
  6. mlaflamm revised this gist Nov 16, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ As far as we know, this is the only solution that fully supports mapping of `LEF

    We have used straight [sql package](https://golang.org/pkg/database/sql/), [sqlx](https://github.com/jmoiron/sqlx), [squirrel](https://github.com/Masterminds/squirrel)
    with and without `sqlx`, and more recently [sqlboiler](https://github.com/volatiletech/sqlboiler).
    The latter is an ORM rather than an SQL builder but we loved the type safety with code generation.
    The latter is an ORM rather than an SQL builder but we love the type safety with code generation.
    Also their [null](https://github.com/volatiletech/null) types package is a breeze to work with.
    But over time, `sqlboiler` being an ORM, showed its limitations in terms of performance and flexibility.
    Yes this is possible to revert to raw SQL but then we lose some of the type safety.
  7. mlaflamm revised this gist Nov 16, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    We love [go-jet](https://github.com/go-jet/jet)! We are now using it or migrating it to, in all our projects.
    This is simply the best go SQL builder we have tried so far.
    It is type safe thanks to the code generation and the query result mapping is very powerful.
    It is type safe thanks to the code generation and the [query result mapping](https://github.com/go-jet/jet/wiki/Query-Result-Mapping-(QRM)) is very powerful.
    As far as we know, this is the only solution that fully supports mapping of `LEFT OUTER JOIN` out of the box.

    We have used straight [sql package](https://golang.org/pkg/database/sql/), [sqlx](https://github.com/jmoiron/sqlx), [squirrel](https://github.com/Masterminds/squirrel)
  8. mlaflamm revised this gist Nov 16, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,12 @@ As far as we know, this is the only solution that fully supports mapping of `LEF
    We have used straight [sql package](https://golang.org/pkg/database/sql/), [sqlx](https://github.com/jmoiron/sqlx), [squirrel](https://github.com/Masterminds/squirrel)
    with and without `sqlx`, and more recently [sqlboiler](https://github.com/volatiletech/sqlboiler).
    The latter is an ORM rather than an SQL builder but we loved the type safety with code generation.
    Also their [null](https://github.com/volatiletech/null) types package are a breeze to work with.
    Also their [null](https://github.com/volatiletech/null) types package is a breeze to work with.
    But over time, `sqlboiler` being an ORM, showed its limitations in terms of performance and flexibility.
    Yes this is possible to revert to raw SQL but then we lose some of the type safety.

    When we discovered `go-jet`, we were very excited.
    A type safe SQL builder solution is exactly what we were looking for!
    A type safe SQL builder solution with code generation is exactly what we were looking for!
    Our only complaint was the usage of pointers for nullable values instead of the convenient `null` types.

    After tinkering with multiple ways to generate `go-jet` models with `null` types, we ended up wrapping the jet code generator with a bash script
  9. mlaflamm revised this gist Nov 16, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -14,5 +14,5 @@ When we discovered `go-jet`, we were very excited.
    A type safe SQL builder solution is exactly what we were looking for!
    Our only complaint was the usage of pointers for nullable values instead of the convenient `null` types.

    After tinkering with multiple solutions, we ended up wrapping the jet code generator with a bash script
    After tinkering with multiple ways to generate `go-jet` models with `null` types, we ended up wrapping the jet code generator with a bash script
    that automatically converts the types of the `go-jet` models to our beloved `null` types.
  10. mlaflamm revised this gist Nov 16, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    We love [go-jet](https://github.com/go-jet/jet)! We are now using it or migrating it to, in all our projects.
    This is simply the best go SQL builder we have tried so far.
    It is type safe thanks to the code generation and the query result mapping is very powerful.
    As far as we know, this is the only solution that fully supports mapping of LEFT OUTER JOIN out of the box.
    As far as we know, this is the only solution that fully supports mapping of `LEFT OUTER JOIN` out of the box.

    We have used straight [sql package](https://golang.org/pkg/database/sql/), [sqlx](https://github.com/jmoiron/sqlx), [squirrel](https://github.com/Masterminds/squirrel)
    with and without `sqlx`, and more recently [sqlboiler](https://github.com/volatiletech/sqlboiler).
  11. mlaflamm revised this gist Nov 16, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions jet.sh
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,15 @@
    #!/bin/bash

    # 'rm' and 'mv' are for flattening the directory structure
    # 'rm' and 'mv' are for flattening the annoyingly deep directory structure
    rm -rf jetdb model table
    go run github.com/go-jet/jet/v2/cmd/jet -source=PostgreSQL -host=localhost -port=5432 -user=jetuser -password=jetpass -dbname=jetdb -schema=dvds -path=.
    mv ./jetdb/dvds/* .
    rm -rf jetdb

    # this how we exclude tables
    # this is how we exclude tables
    rm */schema_migrations.go

    # this is the main replacement 'logic'
    if [ "$(uname)" == "Darwin" ]; then
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|int32|int|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*int|null.Int|g'
  12. mlaflamm created this gist Nov 16, 2020.
    18 changes: 18 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    We love [go-jet](https://github.com/go-jet/jet)! We are now using it or migrating it to, in all our projects.
    This is simply the best go SQL builder we have tried so far.
    It is type safe thanks to the code generation and the query result mapping is very powerful.
    As far as we know, this is the only solution that fully supports mapping of LEFT OUTER JOIN out of the box.

    We have used straight [sql package](https://golang.org/pkg/database/sql/), [sqlx](https://github.com/jmoiron/sqlx), [squirrel](https://github.com/Masterminds/squirrel)
    with and without `sqlx`, and more recently [sqlboiler](https://github.com/volatiletech/sqlboiler).
    The latter is an ORM rather than an SQL builder but we loved the type safety with code generation.
    Also their [null](https://github.com/volatiletech/null) types package are a breeze to work with.
    But over time, `sqlboiler` being an ORM, showed its limitations in terms of performance and flexibility.
    Yes this is possible to revert to raw SQL but then we lose some of the type safety.

    When we discovered `go-jet`, we were very excited.
    A type safe SQL builder solution is exactly what we were looking for!
    Our only complaint was the usage of pointers for nullable values instead of the convenient `null` types.

    After tinkering with multiple solutions, we ended up wrapping the jet code generator with a bash script
    that automatically converts the types of the `go-jet` models to our beloved `null` types.
    30 changes: 30 additions & 0 deletions jet.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/bin/bash

    # 'rm' and 'mv' are for flattening the directory structure
    rm -rf jetdb model table
    go run github.com/go-jet/jet/v2/cmd/jet -source=PostgreSQL -host=localhost -port=5432 -user=jetuser -password=jetpass -dbname=jetdb -schema=dvds -path=.
    mv ./jetdb/dvds/* .
    rm -rf jetdb

    # this how we exclude tables
    rm */schema_migrations.go

    if [ "$(uname)" == "Darwin" ]; then
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|int32|int|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*int|null.Int|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*string|null.String|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|*time.Time|null.Time|g'
    find ./model -type f -name '*.go' | xargs sed -i '' -e 's|package model|package model\'$'\nimport "github.com/volatiletech/null/v8"|g'
    elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
    find ./model -type f -name '*.go' | xargs sed -i 's|int32|int|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|*int|null.Int|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|*string|null.String|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|*time.Time|null.Time|g'
    find ./model -type f -name '*.go' | xargs sed -i 's|package model|package model\n\nimport "github.com/volatiletech/null/v8"|g'
    else
    echo "platform $OSTYPE not supported"
    exit 1
    fi

    # this is to removes unused import packages
    find ./model -type f -name '*.go' | xargs go run golang.org/x/tools/cmd/goimports -w