Skip to content

Commit

Permalink
change the zgraph commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng committed Apr 9, 2023
1 parent 8bb5207 commit 2ad8364
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
# vendor/

.idea
/bin
/data
/tools/bin
y.output
69 changes: 36 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
# Copyright 2022 zGraph Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include build/Makefile.env

.PHONY: parser goyacc

parser: tools/bin/goyacc
@echo "bin/goyacc -o parser/parser.y.go"
@tools/bin/goyacc -o parser/parser.y.go parser/parser.y

fmt: tools/bin/gci
tools/bin/gci write $(FILES)

test:
$(GO) test $(PACKAGES)

tools/bin/goyacc:
$(GO) build -o tools/bin/goyacc ./parser/goyacc/

tools/bin/gci:
cd tools && $(GO) build -o ./bin/gci github.com/daixiang0/gci
# Copyright 2022 zGraph Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include build/Makefile.env

.PHONY: parser goyacc

build:
$(GO) build -o bin/zgraph ./cmd/zgraph

parser: tools/bin/goyacc
@echo "bin/goyacc -o parser/parser.y.go"
@tools/bin/goyacc -o parser/parser.y.go parser/parser.y

fmt: tools/bin/gci
tools/bin/gci write $(FILES)

test:
$(GO) test $(PACKAGES)

tools/bin/goyacc:
$(GO) build -o tools/bin/goyacc ./parser/goyacc/

tools/bin/gci:
cd tools && $(GO) build -o ./bin/gci github.com/daixiang0/gci
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# zgraph
# What is zGraph
[![Go Reference](https://pkg.go.dev/badge/github.com/vescale/zgraph.svg)](https://pkg.go.dev/github.com/vescale/zgraph)
[![GitHub Actions](https://github.com/vescale/zgraph/workflows/Check/badge.svg)](https://github.com/vescale/zgraph/actions?query=workflow%3ACheck)

An embeddable graph database for large-scale vertices and edges.
zGraph is a [PGQL](https://pgql-lang.org/)-compatible embeddable graph database for large-scale vertices.
You can find the specification [here](https://pgql-lang.org/spec/1.5/).

## Installation

```bash
go get -u github.com/vescale/zgraph
```

## Usage
## Quick Start

zGraph implements driver for [database/sql](https://golang.org/pkg/database/sql/). To use zGraph, you can simply import zGraph package and use `zgraph` as the driver name in `sql.Open`.
### Playground

zGraph uses [PGQL](https://pgql-lang.org/) as its query language. You can find the specification [here](https://pgql-lang.org/spec/1.5/).
```bash
> make build
> ./bin/zgraph play
```

### Build Application
zGraph implements driver for [database/sql](https://golang.org/pkg/database/sql/). To use zGraph, you can simply import zGraph package and use `zgraph` as the driver name in `sql.Open`.

Here is an example of how to use create a graph and query it. The graph is an example in [PGQL specification](https://pgql-lang.org/spec/1.5/#edge-patterns).

Expand Down
58 changes: 52 additions & 6 deletions cmd/zgraph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,50 @@ import (
)

type options struct {
dataDir string
global struct {
dataDir string
}
play struct {
}
serve struct {
}
}

func main() {
var opt options
cmd := cobra.Command{
Use: "zgraph --data <dirname>",
Use: "zgraph [command] [flags]",
Long: `zgraph is a command line tool for wrapping the embeddable graph
database 'github.com/vescale/zgraph'', and provide a convenient
approach to experiencing the power to graph database`,
Example: strings.TrimLeft(`
zgraph play # Launch a zGraph playground
zgraph play --datadir ./test # Specify the data directory of the playground
zgraph service # Launch a zGraph as a data service`, "\n"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
SilenceErrors: true,
DisableFlagsInUseLine: true,
}

// Global options
cmd.Flags().StringVarP(&opt.global.dataDir, "datadir", "D", "./data", "Specify the data directory path")

// Subcommands
cmd.AddCommand(playCmd(&opt))
cmd.AddCommand(servCmd(&opt))

err := cmd.Execute()
cobra.CheckErr(err)
}

func playCmd(opt *options) *cobra.Command {
cmd := &cobra.Command{
Use: "play -D <dirname>",
Short: "Run the zgraph as a playground",
RunE: func(cmd *cobra.Command, args []string) error {
db, err := sql.Open("zgraph", opt.dataDir)
db, err := sql.Open("zgraph", opt.global.dataDir)
if err != nil {
return err
}
Expand All @@ -58,10 +93,21 @@ func main() {
SilenceErrors: true,
}

cmd.Flags().StringVarP(&opt.dataDir, "data", "D", "./data", "Specify the data directory path")
return cmd
}

err := cmd.Execute()
cobra.CheckErr(err)
func servCmd(opt *options) *cobra.Command {
cmd := &cobra.Command{
Use: "service -D <dirname> -L :8080 --apis api.yaml",
Short: "Run the zgraph as a data service instance",

This comment has been minimized.

Copy link
@sleepymole

sleepymole Apr 10, 2023

Collaborator

Does it mean running zgraph in client/server mode?

RunE: func(cmd *cobra.Command, args []string) error {
// TODO: implement the data API.
return nil
},
SilenceErrors: true,
}

return cmd
}

func interact(conn *sql.Conn) {
Expand Down

0 comments on commit 2ad8364

Please sign in to comment.