Skip to content
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
12 changes: 1 addition & 11 deletions internal/db/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewWithConfig(ctx context.Context, connConfig *pgxpool.Config, callbacks ..

type ConnInitCallback = func(context.Context, PgxIface) error

// Init creates a new pool, check connection is establised. If not retries connection 3 times with delay 1s
// Init checks if connection is establised. If not, retries connection 3 times with delay 1s
func Init(ctx context.Context, db PgxPoolIface, init ConnInitCallback) error {
var backoff = retry.WithMaxRetries(3, retry.NewConstant(1*time.Second))
logger := log.GetLogger(ctx)
Expand All @@ -87,13 +87,3 @@ func DoesSchemaExist(ctx context.Context, conn PgxIface, schema string) (bool, e
err := conn.QueryRow(ctx, sqlSchemaExists, schema).Scan(&exists)
return exists, err
}

// GetTableColumns returns the list of columns for a given table
func GetTableColumns(ctx context.Context, conn PgxIface, table string) (cols []string, err error) {
sql := `SELECT attname FROM pg_attribute a WHERE a.attrelid = to_regclass($1) and a.attnum > 0 and not a.attisdropped`
r, err := conn.Query(ctx, sql, table)
if err != nil {
return
}
return pgx.CollectRows(r, pgx.RowTo[string])
}
18 changes: 0 additions & 18 deletions internal/db/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ import (

var ctx = context.Background()

func TestGetTableColumns(t *testing.T) {
conn, err := pgxmock.NewPool()
assert.NoError(t, err)

conn.ExpectQuery("SELECT attname").
WithArgs("foo").
WillReturnError(errors.New("expected"))
_, err = db.GetTableColumns(ctx, conn, "foo")
assert.Error(t, err)

conn.ExpectQuery("SELECT attname").
WithArgs("foo").
WillReturnRows(pgxmock.NewRows([]string{"attname"}).AddRow("col1").AddRow("col2"))
cols, err := db.GetTableColumns(ctx, conn, "foo")
assert.NoError(t, err)
assert.Equal(t, []string{"col1", "col2"}, cols)
}

func TestPing(t *testing.T) {
connStr := "foo_boo"
assert.Error(t, db.Ping(ctx, connStr))
Expand Down
Loading