-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: Add means to fetch schema #2006
Merged
AndrewSisley
merged 7 commits into
sourcenetwork:develop
from
AndrewSisley:1993-get-schemas
Oct 27, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c2d837c
Add GetSchemaByVersionID
AndrewSisley 8508736
Add GetAllSchema
AndrewSisley 8246ee1
Add GetSchemaByRoot
AndrewSisley 208267e
Add GetSchemaByName
AndrewSisley d9dffa2
PR FIXUP - Rework cli array stuff
AndrewSisley 28ad92d
PR FIXUP - Pluralize schema(s)
AndrewSisley efdf13b
PR FIXUP - Reorder switch statement
AndrewSisley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2023 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
) | ||
|
||
func MakeSchemaDescribeCommand() *cobra.Command { | ||
var name string | ||
var root string | ||
var versionID string | ||
|
||
var cmd = &cobra.Command{ | ||
Use: "describe", | ||
Short: "View schema descriptions.", | ||
Long: `Introspect schema types. | ||
|
||
Example: view all schemas | ||
defradb client schema describe | ||
|
||
Example: view schemas by name | ||
defradb client schema describe --name User | ||
|
||
Example: view schemas by root | ||
defradb client schema describe --root bae123 | ||
|
||
Example: view a single schema by version id | ||
defradb client schema describe --version bae123 | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
store := mustGetStoreContext(cmd) | ||
|
||
var schemas []client.SchemaDescription | ||
switch { | ||
case versionID != "": | ||
schema, err := store.GetSchemaByVersionID(cmd.Context(), versionID) | ||
if err != nil { | ||
return err | ||
} | ||
return writeJSON(cmd, schema) | ||
|
||
case root != "": | ||
s, err := store.GetSchemasByRoot(cmd.Context(), root) | ||
if err != nil { | ||
return err | ||
} | ||
schemas = s | ||
|
||
case name != "": | ||
s, err := store.GetSchemasByName(cmd.Context(), name) | ||
if err != nil { | ||
return err | ||
} | ||
schemas = s | ||
|
||
default: | ||
s, err := store.GetAllSchemas(cmd.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
schemas = s | ||
} | ||
|
||
return writeJSON(cmd, schemas) | ||
}, | ||
} | ||
cmd.PersistentFlags().StringVar(&name, "name", "", "Schema name") | ||
cmd.PersistentFlags().StringVar(&root, "root", "", "Schema root") | ||
cmd.PersistentFlags().StringVar(&versionID, "version", "", "Schema Version ID") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: It would be good to add a check after the switch to check if name and versionID were given that they are actually related like you did with collections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was in two minds if this should behave like the collection stuff, this is different though, as they are not going to be acting on the collection (saving docs and the like). I'll revisit today and see what happens.
- [ ] Revisit multi param schema describe stuffThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if not acting on it, it would be weird to return a set of results event if the provided params make no sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to close this thread as it should match whatever we decide in #2006 (comment)