Skip to content

Commit

Permalink
fix: schema query
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahanmmi committed Dec 18, 2024
1 parent 01fbbb7 commit c107e46
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/cloudql/sdk/extra/rego/rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ func NewRegoEngine(ctx context.Context, logger *zap.Logger) {
return
}
time.Sleep(10 * time.Second)
continue
}
engine.db = db
break
}

tries = 5
Expand All @@ -60,8 +62,10 @@ func NewRegoEngine(ctx context.Context, logger *zap.Logger) {
return
}
time.Sleep(10 * time.Second)
continue
}
engine.regoFunctions = functions
break
}

port := os.Getenv("REGO_PORT")
Expand All @@ -80,7 +84,7 @@ func NewRegoEngine(ctx context.Context, logger *zap.Logger) {
}

func (r *RegoEngine) getRegoFunctionForTables(ctx context.Context) ([]func(*rego.Rego), error) {
rows, err := r.db.Query(ctx, "SELECT table_name FROM information_schema.tables WHERE table_schema NOT IN $1", excludedTableSchema)
rows, err := r.db.Query(ctx, "SELECT table_name FROM information_schema.tables WHERE table_schema NOT IN ($1)", excludedTableSchema)
if err != nil {
r.logger.Error("Unable to query database", zap.Error(err))
return nil, err
Expand All @@ -103,7 +107,7 @@ func (r *RegoEngine) getRegoFunctionForTables(ctx context.Context) ([]func(*rego
Memoize: true,
Nondeterministic: true,
}, func(bctx rego.BuiltinContext, terms []*ast.Term) (*ast.Term, error) {
rows, err := r.db.Query(bctx.Context, "SELECT * FROM $1", tableName)
rows, err := r.db.Query(bctx.Context, fmt.Sprintf("SELECT * FROM %s", tableName))
if err != nil {
r.logger.Error("Unable to query database", zap.Error(err), zap.String("table", tableName))
return nil, err
Expand Down

0 comments on commit c107e46

Please sign in to comment.