Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: support query by name in OpenAPI (#3708)

ecmadao71aae4fc8dc4
diff --git a/api/instance.go b/api/instance.go
index 601aa613d5..7d66dd23c3 100644
--- a/api/instance.go
+++ b/api/instance.go
@@ -72,6 +72,7 @@ type InstanceFind struct {
EnvironmentID *int
// Domain specific fields
+ Name *string
Host *string
Port *string
}
diff --git a/server/openapi_environment.go b/server/openapi_environment.go
index 4722a4a885..1e0c368f57 100644
--- a/server/openapi_environment.go
+++ b/server/openapi_environment.go
@@ -26,9 +26,14 @@ func (s *Server) registerOpenAPIRoutesForEnvironment(g *echo.Group) {
func (s *Server) listEnvironment(c echo.Context) error {
ctx := c.Request().Context()
rowStatus := api.Normal
- envList, err := s.store.FindEnvironment(ctx, &api.EnvironmentFind{
+ find := &api.EnvironmentFind{
RowStatus: &rowStatus,
- })
+ }
+ if name := c.QueryParam("name"); name != "" {
+ find.Name = &name
+ }
+
+ envList, err := s.store.FindEnvironment(ctx, find)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch environment list").SetInternal(err)
}
diff --git a/server/openapi_instance.go b/server/openapi_instance.go
index 6a64d04057..5435b329fc 100644
--- a/server/openapi_instance.go
+++ b/server/openapi_instance.go
@@ -24,9 +24,14 @@ func (s *Server) registerOpenAPIRoutesForInstance(g *echo.Group) {
func (s *Server) listInstance(c echo.Context) error {
ctx := c.Request().Context()
rowStatus := api.Normal
- instanceList, err := s.store.FindInstance(ctx, &api.InstanceFind{
+ find := &api.InstanceFind{
RowStatus: &rowStatus,
- })
+ }
+ if name := c.QueryParam("name"); name != "" {
+ find.Name = &name
+ }
+
+ instanceList, err := s.store.FindInstance(ctx, find)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch instance list").SetInternal(err)
}
diff --git a/store/instance.go b/store/instance.go
index 054df04353..4a5ade5318 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -657,6 +657,9 @@ func findInstanceQuery(find *api.InstanceFind) (string, []interface{}) {
if v := find.Port; v != nil {
where, args = append(where, fmt.Sprintf("port = $%d", len(args)+1)), append(args, *v)
}
+ if v := find.Name; v != nil {
+ where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
+ }
return strings.Join(where, " AND "), args
}