Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for postgres #60

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use_repo(
"com_github_gorilla_mux",
"com_github_hashicorp_go_multierror",
"com_github_hedwigz_entviz",
"com_github_jackc_pgx_v5",
"com_github_machinebox_graphql",
"com_github_mattn_go_sqlite3",
"com_github_pkg_errors",
Expand Down
3 changes: 3 additions & 0 deletions cmd/bb_portal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ go_library(
"@com_github_buildbarn_bb_storage//pkg/util",
"@com_github_fsnotify_fsnotify//:fsnotify",
"@com_github_gorilla_mux//:mux",
"@com_github_jackc_pgx_v5//stdlib",
"@com_github_mattn_go_sqlite3//:go-sqlite3",
"@io_entgo_contrib//entgql",
"@io_entgo_ent//dialect",
"@io_entgo_ent//dialect/sql",
"@org_golang_google_genproto//googleapis/devtools/build/v1:build",
"@org_golang_google_grpc//:grpc",
],
Expand Down
24 changes: 20 additions & 4 deletions cmd/bb_portal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"database/sql"
"flag"
"log/slog"
"net/http"
Expand All @@ -11,10 +12,13 @@ import (
"time"

"entgo.io/contrib/entgql"
"entgo.io/ent/dialect"
entsql "entgo.io/ent/dialect/sql"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/fsnotify/fsnotify"
"github.com/gorilla/mux"
_ "github.com/jackc/pgx/v5/stdlib"
_ "github.com/mattn/go-sqlite3"
build "google.golang.org/genproto/googleapis/devtools/build/v1"
go_grpc "google.golang.org/grpc"
Expand Down Expand Up @@ -65,10 +69,22 @@ func main() {
return util.StatusWrap(err, "Failed to apply global configuration options")
}

dbClient, err := ent.Open(
*dsDriver,
*dsURL,
)
var dbClient *ent.Client

if *dsDriver == "pgx" {
db, err := sql.Open("pgx", *dsURL)
if err != nil {
fatal("Failed to open pgx database", "err", err)
}
drv := entsql.OpenDB(dialect.Postgres, db)
dbClient = ent.NewClient(ent.Driver(drv))
} else {
dbClient, err = ent.Open(
*dsDriver,
*dsURL,
)
}

if err != nil {
return util.StatusWrapf(err, "Failed to open ent client")
}
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/hashicorp/go-multierror v1.1.1
github.com/hedwigz/entviz v0.0.0-20221011080911-9d47f6f1d818
github.com/jackc/pgx/v5 v5.7.1
github.com/machinebox/graphql v0.2.2
github.com/mattn/go-sqlite3 v1.14.22
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -56,6 +57,9 @@ require (
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/matryer/is v1.4.1 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
Expand Down
Loading