Skip to content

Commit

Permalink
feat(query): describe schema with internals
Browse files Browse the repository at this point in the history
This commits implements DescribeSchemaWithInternals which returns the output of Scylla DESCRIBE SCHEMA WITH INTERNALS query.
  • Loading branch information
Michal-Leszczynski authored and karol-kokoszka committed Jun 20, 2024
1 parent dee03fc commit 9a7e886
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/util/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package query
import (
"strings"

"github.com/pkg/errors"
"github.com/scylladb/go-set/strset"
"github.com/scylladb/gocqlx/v2"
"github.com/scylladb/gocqlx/v2/qb"
Expand Down Expand Up @@ -46,3 +47,34 @@ func GetTableVersion(s gocqlx.Session, keyspace, table string) (string, error) {

return version, nil
}

// DescribedSchema describes output of DESCRIBE SCHEMA WITH INTERNALS.
type DescribedSchema []DescribedSchemaRow

// DescribedSchemaRow describes a single row returned by DESCRIBE SCHEMA WITH INTERNALS.
type DescribedSchemaRow struct {
Keyspace string `json:"keyspace"`
Type string `json:"type"`
Name string `json:"name"`
CQLStmt string `json:"cql_stmt"`
}

// DescribeSchemaWithInternals returns the output of DESCRIBE SCHEMA WITH INTERNALS query parsed into DescribedSchema.
func DescribeSchemaWithInternals(session gocqlx.Session) (DescribedSchema, error) {
it := session.Query("DESCRIBE SCHEMA WITH INTERNALS", nil).Iter()
var ks, t, name, cql string
var schema DescribedSchema
for it.Scan(&ks, &t, &name, &cql) {
schema = append(schema, DescribedSchemaRow{
Keyspace: ks,
Type: t,
Name: name,
CQLStmt: cql,
})
}

if err := it.Close(); err != nil {
return DescribedSchema{}, errors.Wrap(err, "describe schema with internals")
}
return schema, nil
}

0 comments on commit 9a7e886

Please sign in to comment.