query

package
v0.0.0-...-fa720cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "query <graph> <query expression>",
	Short: "Query a graph",
	Long: `Query a graph.
Example:
    grip query example-graph 'V().hasLabel("Variant").out().limit(5)'`,
	Args: cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		vm := goja.New()

		us, err := underscore.Asset("underscore.js")
		if err != nil {
			return fmt.Errorf("failed to load underscore.js")
		}
		if _, err := vm.RunString(string(us)); err != nil {
			return err
		}

		gripqlString, err := gripqljs.Asset("gripql.js")
		if err != nil {
			return fmt.Errorf("failed to load gripql.js")
		}
		if _, err := vm.RunString(string(gripqlString)); err != nil {
			return err
		}

		queryString := args[1]
		val, err := vm.RunString(queryString)
		if err != nil {
			return err
		}

		queryJSON, err := json.Marshal(val)
		if err != nil {
			return err
		}

		query := gripql.GraphQuery{}
		err = protojson.Unmarshal(queryJSON, &query)
		if err != nil {
			return err
		}
		query.Graph = args[0]

		conn, err := gripql.Connect(rpc.ConfigWithDefaults(host), true)
		if err != nil {
			return err
		}

		res, err := conn.Traversal(&query)
		if err != nil {
			return err
		}

		for row := range res {
			rowString, _ := protojson.Marshal(row)
			fmt.Printf("%s\n", rowString)
		}
		return nil
	},
}

Cmd is the declaration of the command line

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL