|
| 1 | +# modusGraph Basic CLI Example |
| 2 | + |
| 3 | +This command-line application demonstrates basic operations with modusGraph, a graph database |
| 4 | +library. The example implements CRUD operations (Create, Read, Update, Delete) for a simple `Thread` |
| 5 | +entity type. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +- Go 1.24 or higher |
| 10 | +- Access to either: |
| 11 | + - A local filesystem (for file-based storage) |
| 12 | + - A Dgraph cluster (for distributed storage) |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +```bash |
| 17 | +# Navigate to the examples/basic directory |
| 18 | +cd examples/basic |
| 19 | + |
| 20 | +# Run directly |
| 21 | +go run main.go [options] |
| 22 | + |
| 23 | +# Or build and then run |
| 24 | +go build -o modusgraph-cli |
| 25 | +./modusgraph-cli [options] |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +```sh |
| 31 | +Usage of ./main: |
| 32 | + --dir string Directory where modusGraph will initialize, note the directory must exist and you must have write access |
| 33 | + --addr string Hostname/port where modusGraph will access for I/O (if not using the dir flag) |
| 34 | + --cmd string Command to execute: create, update, delete, get, list (default "create") |
| 35 | + --author string Created by (for create and update) |
| 36 | + --name string Name of the Thread (for create and update) |
| 37 | + --uid string UID of the Thread (required for update, delete, and get) |
| 38 | + --workspace string Workspace ID (for create, update, and filter for list) |
| 39 | +``` |
| 40 | + |
| 41 | +**Note**: You must provide either `--dir` (for file-based storage) or `--addr` (for Dgraph cluster) |
| 42 | +parameter. |
| 43 | + |
| 44 | +## Commands |
| 45 | + |
| 46 | +### Create a Thread |
| 47 | + |
| 48 | +```bash |
| 49 | +go run main.go --dir /tmp/modusgraph-data --cmd create --name "New Thread" --workspace "workspace-123" --author "user-456" |
| 50 | +``` |
| 51 | + |
| 52 | +**Note**: Due to the intricacies of how Dgraph handles unique fields and upserts in its core |
| 53 | +package, unique field checks and upsert operations are not supported (yet) when using the local |
| 54 | +(file-based) mode. These operations work properly when using a full Dgraph cluster (--addr option), |
| 55 | +but the simplified file-based mode does not support the constraint enforcement mechanisms required |
| 56 | +for uniqueness guarantees. The workaround here would be to check for the Thread name and workspace |
| 57 | +ID before creating a new Thread. |
| 58 | + |
| 59 | +### Update a Thread |
| 60 | + |
| 61 | +```bash |
| 62 | +go run main.go --dir /tmp/modusgraph-data --cmd update --uid "0x123" --name "Updated Thread" --workspace "workspace-123" --author "user-456" |
| 63 | +``` |
| 64 | + |
| 65 | +### Get a Thread by UID |
| 66 | + |
| 67 | +```bash |
| 68 | +go run main.go --dir /tmp/modusgraph-data --cmd get --uid "0x123" |
| 69 | +``` |
| 70 | + |
| 71 | +### Delete a Thread |
| 72 | + |
| 73 | +```bash |
| 74 | +go run main.go --dir /tmp/modusgraph-data --cmd delete --uid "0x123" |
| 75 | +``` |
| 76 | + |
| 77 | +### List All Threads |
| 78 | + |
| 79 | +```bash |
| 80 | +go run main.go --dir /tmp/modusgraph-data --cmd list |
| 81 | +``` |
| 82 | + |
| 83 | +### List Threads by Workspace |
| 84 | + |
| 85 | +```bash |
| 86 | +go run main.go --dir /tmp/modusgraph-data --cmd list --workspace "workspace-123" |
| 87 | +``` |
| 88 | + |
| 89 | +## Using with Dgraph |
| 90 | + |
| 91 | +To use with a Dgraph cluster instead of file-based storage: |
| 92 | + |
| 93 | +```bash |
| 94 | +go run main.go --addr localhost:9080 --cmd list |
| 95 | +``` |
| 96 | + |
| 97 | +## Output Format |
| 98 | + |
| 99 | +The application displays data in a tabular format: |
| 100 | + |
| 101 | +- For single Thread retrieval (`get`), fields are displayed in a vertical layout |
| 102 | +- For multiple Thread retrieval (`list`), records are displayed in a horizontal table |
| 103 | + |
| 104 | +## Logging |
| 105 | + |
| 106 | +The application uses structured logging with different verbosity levels. To see more detailed logs |
| 107 | +including query execution, you can modify the `stdr.SetVerbosity(1)` line in the code to a higher |
| 108 | +level. |
0 commit comments