Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ShowSpaces for SessionPool #313

Merged
merged 3 commits into from
Feb 4, 2024
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
5 changes: 4 additions & 1 deletion label.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func (edge LabelSchema) BuildDropEdgeQL() string {
return q
}

// For internal use
type LabelName struct {
Name string `nebula:"Name"`
}

type SpaceName struct {
Name string `nebula:"Name"`
}
12 changes: 12 additions & 0 deletions session_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ func (pool *SessionPool) ExecuteAndCheck(q string) (*ResultSet, error) {
return rs, nil
}

func (pool *SessionPool) ShowSpaces() ([]SpaceName, error) {
rs, err := pool.ExecuteAndCheck("SHOW SPACES;")
if err != nil {
return nil, err
}

var names []SpaceName
rs.Scan(&names)

return names, nil
}

func (pool *SessionPool) ShowTags() ([]LabelName, error) {
rs, err := pool.ExecuteAndCheck("SHOW TAGS;")
if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion session_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ func TestSessionPoolApplySchema(t *testing.T) {
}
defer sessionPool.Close()

spaces, err := sessionPool.ShowSpaces()
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(spaces), "should have at least 1 space")
var spaceNames []string
for _, space := range spaces {
spaceNames = append(spaceNames, space.Name)
}
assert.Contains(t, spaceNames, "test_space_schema", "should have test_space_schema")

tagSchema := LabelSchema{
Name: "account",
Fields: []LabelFieldSchema{
Expand Down Expand Up @@ -423,7 +434,7 @@ func TestSessionPoolApplySchema(t *testing.T) {
assert.Equal(t, "email", labels[1].Field, "field name should be email")
assert.Equal(t, "string", labels[1].Type, "field type should be string")
assert.Equal(t, "phone", labels[2].Field, "field name should be phone")
assert.Equal(t, "int64", labels[2].Type, "field type should be string")
assert.Equal(t, "int64", labels[2].Type, "field type should be int64")

edgeSchema := LabelSchema{
Name: "account_email",
Expand Down
Loading