forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add means to fetch schema (sourcenetwork#2006)
## Relevant issue(s) Resolves sourcenetwork#1993 ## Description Adds means to fetch schema. Adds a bunch of funcs to the clients to allow fetching of schema(versions) defined in the system. When the set-default stuff got merged, users were no longer guaranteed (at least on init) to be able to view the schema ids they have created, this change allows them to view them when ever they like.
- Loading branch information
1 parent
c90a88d
commit 268241d
Showing
17 changed files
with
1,152 additions
and
0 deletions.
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.