|
1 | 1 | # Daptin CLI |
2 | 2 |
|
3 | | -Command-line interface for [Daptin](https://github.com/daptin/daptin) Backend-as-a-Service. |
4 | | - |
5 | | -Built with TypeScript, inspired by [daptin-js-client](https://github.com/artpar/daptin-js-client). |
6 | | - |
7 | | -## Installation |
8 | | - |
9 | | -```bash |
10 | | -npm install -g daptin-cli |
11 | | -``` |
12 | | - |
13 | | -Or build from source: |
14 | | - |
15 | | -```bash |
16 | | -git clone https://github.com/daptin/daptin-cli.git |
17 | | -cd daptin-cli |
18 | | -npm install |
19 | | -npm run build |
20 | | -npm link |
21 | | -``` |
22 | | - |
23 | | -## Quick Start |
24 | | - |
25 | | -```bash |
26 | | -# Add a Daptin server |
27 | | -daptin-cli config add local http://localhost:6336 |
28 | | - |
29 | | -# Sign in |
30 | | -daptin-cli signin admin@example.com |
31 | | - |
32 | | -# List all tables |
33 | | -daptin-cli tables |
34 | | - |
35 | | -# List records from a table |
36 | | -daptin-cli list user_account --page-size 20 |
37 | | - |
38 | | -# Get a single record |
39 | | -daptin-cli get user_account <reference_id> |
40 | | -``` |
41 | | - |
42 | | -## Configuration |
43 | | - |
44 | | -The CLI stores configuration in `~/.daptin/config.yaml`. You can manage multiple server contexts: |
45 | | - |
46 | | -```bash |
47 | | -# Add servers |
48 | | -daptin-cli config add local http://localhost:6336 |
49 | | -daptin-cli config add production https://api.example.com |
50 | | - |
51 | | -# Switch active server |
52 | | -daptin-cli config use production |
53 | | - |
54 | | -# List all servers |
55 | | -daptin-cli config list |
56 | | - |
57 | | -# Show current context |
58 | | -daptin-cli config show |
59 | | - |
60 | | -# Remove a server |
61 | | -daptin-cli config remove local |
62 | | -``` |
63 | | - |
64 | | -Override the endpoint on any command with `--endpoint`: |
65 | | - |
66 | | -```bash |
67 | | -daptin-cli --endpoint http://localhost:6336 tables |
68 | | -``` |
69 | | - |
70 | | -## Global Options |
71 | | - |
72 | | -| Flag | Description | Default | |
73 | | -|------|-------------|---------| |
74 | | -| `-e, --endpoint <url>` | Daptin server endpoint | from config | |
75 | | -| `-c, --config <path>` | Config file path | `~/.daptin/config.yaml` | |
76 | | -| `-o, --output <format>` | Output format (`table`, `json`) | `table` | |
77 | | -| `-t, --token <token>` | Auth token | from config | |
78 | | -| `--debug` | Enable debug output | `false` | |
79 | | - |
80 | | -## Commands |
81 | | - |
82 | | -### Authentication |
| 3 | +CLI for talking to [Daptin server](https://github.com/daptin/daptin) |
83 | 4 |
|
84 | 5 | ```bash |
85 | | -# Create a new account |
86 | | -daptin-cli signup user@example.com |
87 | | - |
88 | | -# Sign in (prompts for password) |
89 | | -daptin-cli signin user@example.com |
90 | | - |
91 | | -# Sign in with 2FA |
92 | | -daptin-cli signin-2fa user@example.com |
93 | | - |
94 | | -# Show current user info |
95 | | -daptin-cli whoami |
96 | | -``` |
97 | | - |
98 | | -### Schema Discovery |
99 | | - |
100 | | -```bash |
101 | | -# List all tables |
102 | | -daptin-cli tables |
103 | | -daptin-cli tables --columns table_name,is_top_level,default_permission |
104 | | - |
105 | | -# Describe a table (columns, relations, actions) |
106 | | -daptin-cli describe user_account |
107 | | -daptin-cli describe product --columns ColumnName,ColumnType,DataType,IsNullable |
108 | | -``` |
109 | | - |
110 | | -### CRUD Operations |
111 | | - |
112 | | -```bash |
113 | | -# List records |
114 | | -daptin-cli list product |
115 | | -daptin-cli list product --page-size 50 --page 2 |
116 | | -daptin-cli list product --columns name,price,reference_id |
117 | | -daptin-cli list product --sort -price,name |
118 | | -daptin-cli list product --include category_id |
119 | | - |
120 | | -# Get a single record |
121 | | -daptin-cli get product <reference_id> |
122 | | -daptin-cli get product <reference_id> --columns name,price |
123 | | - |
124 | | -# Create a record |
125 | | -daptin-cli create product --data '{"name": "Widget", "price": 9.99}' |
126 | | - |
127 | | -# Update a record |
128 | | -daptin-cli update product <reference_id> --data '{"price": 12.99}' |
129 | | - |
130 | | -# Delete a record |
131 | | -daptin-cli delete product <reference_id> |
132 | | - |
133 | | -# Query relationships |
134 | | -daptin-cli relation customer <reference_id> order_id --page-size 20 |
| 6 | +go get github.com/daptin/daptin-cli |
| 7 | +go install github.com/daptin/daptin-cli |
| 8 | +go build -o daptin-cli |
135 | 9 | ``` |
136 | 10 |
|
137 | | -### Actions |
138 | 11 |
|
| 12 | +Describe a table schema |
139 | 13 | ```bash |
140 | | -# List all actions |
141 | | -daptin-cli actions |
142 | | - |
143 | | -# List actions for a specific table |
144 | | -daptin-cli actions user_account |
145 | | - |
146 | | -# Show action schema (input/output fields) |
147 | | -daptin-cli action-describe user_account signin |
148 | | - |
149 | | -# Execute an action |
150 | | -daptin-cli execute user_account generate_jwt_token --data '{"email": "user@example.com"}' |
151 | | - |
152 | | -# Execute an instance-level action |
153 | | -daptin-cli execute order mark_shipped --id <order_reference_id> --data '{"tracking_number": "ABC123"}' |
| 14 | +./daptin-cli --output table describe table world |
154 | 15 | ``` |
155 | 16 |
|
156 | | -### Aggregation |
| 17 | +List items of a table |
157 | 18 |
|
158 | | -```bash |
159 | | -# Count records |
160 | | -daptin-cli aggregate product --columns count |
161 | | - |
162 | | -# Sum and average |
163 | | -daptin-cli aggregate product --columns "count,sum(price),avg(price)" |
164 | | - |
165 | | -# Group by |
166 | | -daptin-cli aggregate order --columns "status,count,sum(total)" --group status |
167 | | - |
168 | | -# With filters |
169 | | -daptin-cli aggregate product --columns "count,avg(price)" --filter "gt(price,100)" |
170 | | - |
171 | | -# With limit and sort |
172 | | -daptin-cli aggregate order --columns "status,count" --group status --sort "-count" --limit 10 |
173 | | -``` |
174 | | - |
175 | | -### Output Formats |
| 19 | + ./daptin-cli list --pageSize 50 --columns <col1>,<col2> <tableName> |
176 | 20 |
|
177 | 21 | ```bash |
178 | | -# Table output (default) |
179 | | -daptin-cli list product --output table |
180 | | - |
181 | | -# JSON output |
182 | | -daptin-cli list product --output json |
183 | | - |
184 | | -# JSON output piped to jq |
185 | | -daptin-cli list product -o json | jq '.[].name' |
| 22 | +./daptin-cli list --pageSize 50 --columns reference_id,table_name world |
186 | 23 | ``` |
187 | 24 |
|
188 | | -## Environment Variables |
189 | 25 |
|
190 | | -| Variable | Description | |
191 | | -|----------|-------------| |
192 | | -| `DAPTIN_CLI_CONFIG` | Path to config file | |
193 | | -| `DAPTIN_ENDPOINT` | Default server endpoint | |
| 26 | +Get one row by reference_id |
194 | 27 |
|
195 | | -## Development |
| 28 | + ./daptin-cli get-by-id --columns reference_id,table_name <table_name> <reference_id> |
196 | 29 |
|
197 | 30 | ```bash |
198 | | -# Install dependencies |
199 | | -npm install |
200 | | - |
201 | | -# Run in development mode |
202 | | -npx tsx src/index.ts tables |
203 | | - |
204 | | -# Type check |
205 | | -npm run typecheck |
206 | | - |
207 | | -# Build |
208 | | -npm run build |
| 31 | +./daptin-cli get-by-id --columns reference_id,table_name,is_top_level world 019228bb-a7cd-773b-a465-c92d7c54d956 |
209 | 32 | ``` |
210 | 33 |
|
211 | | -## License |
212 | | - |
213 | | -MIT |
0 commit comments