-
Notifications
You must be signed in to change notification settings - Fork 8
/
read_schema.go
56 lines (45 loc) · 2.17 KB
/
read_schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package database
import (
"context"
"fmt"
"github.com/kwilteam/kwil-db/cmd/common/display"
"github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/common"
"github.com/kwilteam/kwil-db/cmd/kwil-cli/config"
clientType "github.com/kwilteam/kwil-db/core/types/client"
"github.com/spf13/cobra"
)
// TODO: @brennan: make the way this prints out the metadata more readable
var (
readSchemaLong = `Read schema is used to view the details of a deployed database schema.
You can either specify the database to execute this against with the ` + "`" + `--name` + "`" + ` and ` + "`" + `--owner` + "`" + `
flags, or you can specify the database by passing the database id with the ` + "`" + `--dbid` + "`" + ` flag. If a ` + "`" + `--name` + "`" + `
flag is passed and no ` + "`" + `--owner` + "`" + ` flag is passed, the owner will be inferred from your configured wallet.`
readSchemaExample = `# Reading the schema of the "mydb" database, owned by 0x9228624C3185FCBcf24c1c9dB76D8Bef5f5DAd64
kwil-cli database read-schema --name mydb --owner 0x9228624C3185FCBcf24c1c9dB76D8Bef5f5DAd64`
)
func readSchemaCmd() *cobra.Command {
var cmd = &cobra.Command{
Use: "read-schema",
Short: "Read schema is used to view the details of a deployed database schema.",
Long: readSchemaLong,
Example: readSchemaExample,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return common.DialClient(cmd.Context(), cmd, common.WithoutPrivateKey, func(ctx context.Context, client clientType.Client, conf *config.KwilCliConfig) error {
dbid, err := getSelectedDbid(cmd, conf)
if err != nil {
return display.PrintErr(cmd, fmt.Errorf("you must specify either a database name with the --name, or a database id with the --dbid flag"))
}
schema, err := client.GetSchema(ctx, dbid)
if err != nil {
return display.PrintErr(cmd, fmt.Errorf("error getting schema: %w", err))
}
return display.PrintCmd(cmd, &respSchema{Schema: schema})
})
},
}
cmd.Flags().StringP(nameFlag, "n", "", "the target database name")
cmd.Flags().StringP(ownerFlag, "o", "", "the target database owner")
cmd.Flags().StringP(dbidFlag, "i", "", "the target database id")
return cmd
}