From 6ea4d2c82de80efc87708e5e182034b7c6c2019e Mon Sep 17 00:00:00 2001 From: Gibheer Date: Thu, 5 Sep 2024 19:38:25 +0200 Subject: switch from github.com/lib/pq to github.com/jackc/pgx/v5 lib/pq is out of maintenance for some time now, so switch to the newer more active library. Looks like it finally stabilized after a long time. --- cmd/monfront/main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'cmd/monfront/main.go') diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index f8d8ee7..8943744 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -18,7 +18,7 @@ import ( "time" "github.com/BurntSushi/toml" - "github.com/lib/pq" + _ "github.com/jackc/pgx/v5/stdlib" "golang.org/x/term" ) @@ -107,7 +107,7 @@ func main() { logger := parseLogger(config) - db, err := sql.Open("postgres", config.DB) + db, err := sql.Open("pgx", config.DB) if err != nil { log.Fatalf("could not open database connection: %s", err) } @@ -278,7 +278,7 @@ func checkAction(con *Context) { case "disable": setClause = "enabled = false, updated = now()" case "delete_check": - if _, err := DB.Exec(`delete from checks where id = any ($1::bigint[])`, pq.Array(checks)); err != nil { + if _, err := DB.Exec(`delete from checks where id = any ($1::bigint[])`, checks); err != nil { con.log.Info("could not delete checks", "checks", checks, "error", err) con.Error = "could not delete checks" returnError(http.StatusInternalServerError, con, con.w) @@ -321,7 +321,7 @@ func checkAction(con *Context) { cn.notifier_id, $2 from checks_notify cn join active_checks ac on cn.check_id = ac.check_id - where cn.check_id = any ($1::bigint[])`, pq.Array(&checks), &hostname); err != nil { + where cn.check_id = any ($1::bigint[])`, &checks, &hostname); err != nil { con.log.Info("could not acknowledge check", "error", err) con.Error = "could not acknowledge check" returnError(http.StatusInternalServerError, con, con.w) @@ -334,7 +334,7 @@ func checkAction(con *Context) { } _, err := DB.Exec( "update active_checks set notice = $2 where check_id = any ($1::bigint[]);", - pq.Array(&checks), + &checks, comment) if err != nil { con.w.WriteHeader(http.StatusInternalServerError) @@ -346,7 +346,7 @@ func checkAction(con *Context) { return case "uncomment": _, err := DB.Exec(`update active_checks set notice = null where check_id = any($1::bigint[]);`, - pq.Array(&checks)) + &checks) if err != nil { con.Error = "could not uncomment checks" returnError(http.StatusInternalServerError, con, con.w) @@ -366,7 +366,7 @@ func checkAction(con *Context) { } sql := "update " + setTable + " set " + setClause + " where " + whereColumn + " = any($1::bigint[])" - whereVals = append([]any{pq.Array(&checks)}, whereVals...) + whereVals = append([]any{&checks}, whereVals...) if len(whereFields) > 0 { for i, column := range whereFields { sql = sql + " and " + column + fmt.Sprintf(" = $%d", i+1) -- cgit v1.2.3-70-g09d2