axiodb 20.3.2 → 20.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/.graphifyignore +0 -12
- package/cli/VERSION +0 -1
- package/cli/cmd/auth_management.go +0 -68
- package/cli/cmd/collection.go +0 -169
- package/cli/cmd/connect.go +0 -597
- package/cli/cmd/db.go +0 -171
- package/cli/cmd/db_export.go +0 -66
- package/cli/cmd/db_import.go +0 -84
- package/cli/cmd/document.go +0 -409
- package/cli/cmd/health.go +0 -19
- package/cli/cmd/index.go +0 -101
- package/cli/cmd/ping.go +0 -36
- package/cli/cmd/root.go +0 -38
- package/cli/cmd/transaction.go +0 -191
- package/cli/cmd/version.go +0 -27
- package/cli/go.mod +0 -15
- package/cli/go.sum +0 -20
- package/cli/internal/config/config.go +0 -120
- package/cli/main.go +0 -7
- package/cli/pkg/commands/collection.go +0 -68
- package/cli/pkg/commands/db.go +0 -62
- package/cli/pkg/commands/document.go +0 -203
- package/cli/pkg/commands/health.go +0 -18
- package/cli/pkg/commands/index.go +0 -51
- package/cli/pkg/commands/transaction.go +0 -84
- package/cli/pkg/httpclient/client.go +0 -236
- package/cli/pkg/protocol/auth.go +0 -46
- package/cli/pkg/protocol/client.go +0 -174
- package/cli/pkg/protocol/message.go +0 -75
- package/lib/engine/cli/worker_process.d.ts +0 -6
- package/lib/engine/cli/worker_process.js +0 -63
- package/lib/engine/cli/worker_process.js.map +0 -1
- package/opencode.json +0 -9
package/cli/cmd/document.go
DELETED
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"encoding/json"
|
|
5
|
-
"fmt"
|
|
6
|
-
"os"
|
|
7
|
-
|
|
8
|
-
"github.com/nexoral/axiodb-cli/internal/config"
|
|
9
|
-
"github.com/nexoral/axiodb-cli/pkg/commands"
|
|
10
|
-
"github.com/spf13/cobra"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
var documentCmd = &cobra.Command{
|
|
14
|
-
Use: "document",
|
|
15
|
-
Short: "Document operations",
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var documentInsertCmd = &cobra.Command{
|
|
19
|
-
Use: "insert <json>",
|
|
20
|
-
Short: "Insert a document",
|
|
21
|
-
Args: cobra.ExactArgs(1),
|
|
22
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
23
|
-
cfg, err := config.FromFlags(cmd)
|
|
24
|
-
if err != nil {
|
|
25
|
-
return err
|
|
26
|
-
}
|
|
27
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
28
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var data interface{}
|
|
32
|
-
if err := json.Unmarshal([]byte(args[0]), &data); err != nil {
|
|
33
|
-
return fmt.Errorf("invalid JSON: %w", err)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
client, err := cfg.ConnectAndAuth()
|
|
37
|
-
if err != nil {
|
|
38
|
-
return err
|
|
39
|
-
}
|
|
40
|
-
defer client.Disconnect()
|
|
41
|
-
|
|
42
|
-
resp, err := commands.InsertDocument(client, cfg.DB, cfg.Collection, data)
|
|
43
|
-
if err != nil {
|
|
44
|
-
return err
|
|
45
|
-
}
|
|
46
|
-
return printOutput(cfg.Output, resp)
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
var documentInsertManyCmd = &cobra.Command{
|
|
51
|
-
Use: "insert-many <file>",
|
|
52
|
-
Short: "Insert multiple documents from a JSON file",
|
|
53
|
-
Args: cobra.ExactArgs(1),
|
|
54
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
55
|
-
cfg, err := config.FromFlags(cmd)
|
|
56
|
-
if err != nil {
|
|
57
|
-
return err
|
|
58
|
-
}
|
|
59
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
60
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
data, err := os.ReadFile(args[0])
|
|
64
|
-
if err != nil {
|
|
65
|
-
return fmt.Errorf("read file: %w", err)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
var documents interface{}
|
|
69
|
-
if err := json.Unmarshal(data, &documents); err != nil {
|
|
70
|
-
return fmt.Errorf("invalid JSON: %w", err)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
client, err := cfg.ConnectAndAuth()
|
|
74
|
-
if err != nil {
|
|
75
|
-
return err
|
|
76
|
-
}
|
|
77
|
-
defer client.Disconnect()
|
|
78
|
-
|
|
79
|
-
resp, err := commands.InsertManyDocuments(client, cfg.DB, cfg.Collection, documents)
|
|
80
|
-
if err != nil {
|
|
81
|
-
return err
|
|
82
|
-
}
|
|
83
|
-
return printOutput(cfg.Output, resp)
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
var documentQueryCmd = &cobra.Command{
|
|
88
|
-
Use: "query [query-json]",
|
|
89
|
-
Short: "Query documents",
|
|
90
|
-
Args: cobra.MaximumNArgs(1),
|
|
91
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
92
|
-
cfg, err := config.FromFlags(cmd)
|
|
93
|
-
if err != nil {
|
|
94
|
-
return err
|
|
95
|
-
}
|
|
96
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
97
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
limit, _ := cmd.Flags().GetInt("limit")
|
|
101
|
-
skip, _ := cmd.Flags().GetInt("skip")
|
|
102
|
-
sortStr, _ := cmd.Flags().GetString("sort")
|
|
103
|
-
findOne, _ := cmd.Flags().GetBool("find-one")
|
|
104
|
-
hint, _ := cmd.Flags().GetString("hint")
|
|
105
|
-
|
|
106
|
-
opts := commands.QueryOptions{
|
|
107
|
-
Limit: limit,
|
|
108
|
-
Skip: skip,
|
|
109
|
-
FindOne: findOne,
|
|
110
|
-
Hint: hint,
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if len(args) > 0 {
|
|
114
|
-
var query interface{}
|
|
115
|
-
if err := json.Unmarshal([]byte(args[0]), &query); err != nil {
|
|
116
|
-
return fmt.Errorf("invalid query JSON: %w", err)
|
|
117
|
-
}
|
|
118
|
-
opts.Query = query
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if sortStr != "" {
|
|
122
|
-
var sort interface{}
|
|
123
|
-
if err := json.Unmarshal([]byte(sortStr), &sort); err != nil {
|
|
124
|
-
return fmt.Errorf("invalid sort JSON: %w", err)
|
|
125
|
-
}
|
|
126
|
-
opts.Sort = sort
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
client, err := cfg.ConnectAndAuth()
|
|
130
|
-
if err != nil {
|
|
131
|
-
return err
|
|
132
|
-
}
|
|
133
|
-
defer client.Disconnect()
|
|
134
|
-
|
|
135
|
-
resp, err := commands.QueryDocuments(client, cfg.DB, cfg.Collection, opts)
|
|
136
|
-
if err != nil {
|
|
137
|
-
return err
|
|
138
|
-
}
|
|
139
|
-
return printOutput(cfg.Output, resp)
|
|
140
|
-
},
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
var documentFindByIDsCmd = &cobra.Command{
|
|
144
|
-
Use: "find-by-ids <ids-json>",
|
|
145
|
-
Short: "Find multiple documents by ID",
|
|
146
|
-
Args: cobra.ExactArgs(1),
|
|
147
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
148
|
-
cfg, err := config.FromFlags(cmd)
|
|
149
|
-
if err != nil {
|
|
150
|
-
return err
|
|
151
|
-
}
|
|
152
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
153
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
154
|
-
}
|
|
155
|
-
var ids []string
|
|
156
|
-
if err := json.Unmarshal([]byte(args[0]), &ids); err != nil || len(ids) == 0 {
|
|
157
|
-
return fmt.Errorf("ids must be a non-empty JSON array of strings")
|
|
158
|
-
}
|
|
159
|
-
client, err := cfg.ConnectAndAuth()
|
|
160
|
-
if err != nil {
|
|
161
|
-
return err
|
|
162
|
-
}
|
|
163
|
-
defer client.Disconnect()
|
|
164
|
-
resp, err := commands.FindDocumentsByIDs(client, cfg.DB, cfg.Collection, ids)
|
|
165
|
-
if err != nil {
|
|
166
|
-
return err
|
|
167
|
-
}
|
|
168
|
-
return printOutput(cfg.Output, resp)
|
|
169
|
-
},
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
var documentGetCmd = &cobra.Command{
|
|
173
|
-
Use: "get <id>",
|
|
174
|
-
Short: "Get a document by ID",
|
|
175
|
-
Args: cobra.ExactArgs(1),
|
|
176
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
177
|
-
cfg, err := config.FromFlags(cmd)
|
|
178
|
-
if err != nil {
|
|
179
|
-
return err
|
|
180
|
-
}
|
|
181
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
182
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
client, err := cfg.ConnectAndAuth()
|
|
186
|
-
if err != nil {
|
|
187
|
-
return err
|
|
188
|
-
}
|
|
189
|
-
defer client.Disconnect()
|
|
190
|
-
|
|
191
|
-
resp, err := commands.QueryByID(client, cfg.DB, cfg.Collection, args[0])
|
|
192
|
-
if err != nil {
|
|
193
|
-
return err
|
|
194
|
-
}
|
|
195
|
-
return printOutput(cfg.Output, resp)
|
|
196
|
-
},
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
var documentUpdateCmd = &cobra.Command{
|
|
200
|
-
Use: "update <id> <json>",
|
|
201
|
-
Short: "Update a document by ID",
|
|
202
|
-
Args: cobra.ExactArgs(2),
|
|
203
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
204
|
-
cfg, err := config.FromFlags(cmd)
|
|
205
|
-
if err != nil {
|
|
206
|
-
return err
|
|
207
|
-
}
|
|
208
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
209
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
var updateData interface{}
|
|
213
|
-
if err := json.Unmarshal([]byte(args[1]), &updateData); err != nil {
|
|
214
|
-
return fmt.Errorf("invalid JSON: %w", err)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
client, err := cfg.ConnectAndAuth()
|
|
218
|
-
if err != nil {
|
|
219
|
-
return err
|
|
220
|
-
}
|
|
221
|
-
defer client.Disconnect()
|
|
222
|
-
|
|
223
|
-
resp, err := commands.UpdateDocumentByID(client, cfg.DB, cfg.Collection, args[0], updateData)
|
|
224
|
-
if err != nil {
|
|
225
|
-
return err
|
|
226
|
-
}
|
|
227
|
-
return printOutput(cfg.Output, resp)
|
|
228
|
-
},
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
var documentUpdateByQueryCmd = &cobra.Command{
|
|
232
|
-
Use: "update-by-query <query-json> <update-json>",
|
|
233
|
-
Short: "Update documents by query",
|
|
234
|
-
Args: cobra.ExactArgs(2),
|
|
235
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
236
|
-
cfg, err := config.FromFlags(cmd)
|
|
237
|
-
if err != nil {
|
|
238
|
-
return err
|
|
239
|
-
}
|
|
240
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
241
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
many, _ := cmd.Flags().GetBool("many")
|
|
245
|
-
|
|
246
|
-
var query, updateData interface{}
|
|
247
|
-
if err := json.Unmarshal([]byte(args[0]), &query); err != nil {
|
|
248
|
-
return fmt.Errorf("invalid query JSON: %w", err)
|
|
249
|
-
}
|
|
250
|
-
if err := json.Unmarshal([]byte(args[1]), &updateData); err != nil {
|
|
251
|
-
return fmt.Errorf("invalid update JSON: %w", err)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
client, err := cfg.ConnectAndAuth()
|
|
255
|
-
if err != nil {
|
|
256
|
-
return err
|
|
257
|
-
}
|
|
258
|
-
defer client.Disconnect()
|
|
259
|
-
|
|
260
|
-
resp, err := commands.UpdateDocumentsByQuery(client, cfg.DB, cfg.Collection, query, updateData, !many)
|
|
261
|
-
if err != nil {
|
|
262
|
-
return err
|
|
263
|
-
}
|
|
264
|
-
return printOutput(cfg.Output, resp)
|
|
265
|
-
},
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
var documentDeleteCmd = &cobra.Command{
|
|
269
|
-
Use: "delete <id>",
|
|
270
|
-
Short: "Delete a document by ID",
|
|
271
|
-
Args: cobra.ExactArgs(1),
|
|
272
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
273
|
-
cfg, err := config.FromFlags(cmd)
|
|
274
|
-
if err != nil {
|
|
275
|
-
return err
|
|
276
|
-
}
|
|
277
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
278
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
client, err := cfg.ConnectAndAuth()
|
|
282
|
-
if err != nil {
|
|
283
|
-
return err
|
|
284
|
-
}
|
|
285
|
-
defer client.Disconnect()
|
|
286
|
-
|
|
287
|
-
resp, err := commands.DeleteDocumentByID(client, cfg.DB, cfg.Collection, args[0])
|
|
288
|
-
if err != nil {
|
|
289
|
-
return err
|
|
290
|
-
}
|
|
291
|
-
return printOutput(cfg.Output, resp)
|
|
292
|
-
},
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
var documentDeleteByQueryCmd = &cobra.Command{
|
|
296
|
-
Use: "delete-by-query <query-json>",
|
|
297
|
-
Short: "Delete documents by query",
|
|
298
|
-
Args: cobra.ExactArgs(1),
|
|
299
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
300
|
-
cfg, err := config.FromFlags(cmd)
|
|
301
|
-
if err != nil {
|
|
302
|
-
return err
|
|
303
|
-
}
|
|
304
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
305
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
many, _ := cmd.Flags().GetBool("many")
|
|
309
|
-
|
|
310
|
-
var query interface{}
|
|
311
|
-
if err := json.Unmarshal([]byte(args[0]), &query); err != nil {
|
|
312
|
-
return fmt.Errorf("invalid query JSON: %w", err)
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
client, err := cfg.ConnectAndAuth()
|
|
316
|
-
if err != nil {
|
|
317
|
-
return err
|
|
318
|
-
}
|
|
319
|
-
defer client.Disconnect()
|
|
320
|
-
|
|
321
|
-
resp, err := commands.DeleteDocumentsByQuery(client, cfg.DB, cfg.Collection, query, !many)
|
|
322
|
-
if err != nil {
|
|
323
|
-
return err
|
|
324
|
-
}
|
|
325
|
-
return printOutput(cfg.Output, resp)
|
|
326
|
-
},
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
var documentAggregateCmd = &cobra.Command{
|
|
330
|
-
Use: "aggregate <pipeline-json>",
|
|
331
|
-
Short: "Run aggregation pipeline",
|
|
332
|
-
Args: cobra.ExactArgs(1),
|
|
333
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
334
|
-
cfg, err := config.FromFlags(cmd)
|
|
335
|
-
if err != nil {
|
|
336
|
-
return err
|
|
337
|
-
}
|
|
338
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
339
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
var pipeline interface{}
|
|
343
|
-
if err := json.Unmarshal([]byte(args[0]), &pipeline); err != nil {
|
|
344
|
-
return fmt.Errorf("invalid pipeline JSON: %w", err)
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
client, err := cfg.ConnectAndAuth()
|
|
348
|
-
if err != nil {
|
|
349
|
-
return err
|
|
350
|
-
}
|
|
351
|
-
defer client.Disconnect()
|
|
352
|
-
|
|
353
|
-
resp, err := commands.Aggregate(client, cfg.DB, cfg.Collection, pipeline)
|
|
354
|
-
if err != nil {
|
|
355
|
-
return err
|
|
356
|
-
}
|
|
357
|
-
return printOutput(cfg.Output, resp)
|
|
358
|
-
},
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
var documentCountCmd = &cobra.Command{
|
|
362
|
-
Use: "count",
|
|
363
|
-
Short: "Count total documents",
|
|
364
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
365
|
-
cfg, err := config.FromFlags(cmd)
|
|
366
|
-
if err != nil {
|
|
367
|
-
return err
|
|
368
|
-
}
|
|
369
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
370
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
client, err := cfg.ConnectAndAuth()
|
|
374
|
-
if err != nil {
|
|
375
|
-
return err
|
|
376
|
-
}
|
|
377
|
-
defer client.Disconnect()
|
|
378
|
-
|
|
379
|
-
resp, err := commands.TotalDocuments(client, cfg.DB, cfg.Collection)
|
|
380
|
-
if err != nil {
|
|
381
|
-
return err
|
|
382
|
-
}
|
|
383
|
-
return printOutput(cfg.Output, resp)
|
|
384
|
-
},
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
func init() {
|
|
388
|
-
documentQueryCmd.Flags().Int("limit", 0, "Limit results")
|
|
389
|
-
documentQueryCmd.Flags().Int("skip", 0, "Skip results")
|
|
390
|
-
documentQueryCmd.Flags().String("sort", "", "Sort JSON (e.g., '{\"name\":1}')")
|
|
391
|
-
documentQueryCmd.Flags().Bool("find-one", false, "Find single document")
|
|
392
|
-
documentQueryCmd.Flags().String("hint", "", "Index field name to use")
|
|
393
|
-
|
|
394
|
-
documentUpdateByQueryCmd.Flags().Bool("many", false, "Update multiple documents")
|
|
395
|
-
documentDeleteByQueryCmd.Flags().Bool("many", false, "Delete multiple documents")
|
|
396
|
-
|
|
397
|
-
documentCmd.AddCommand(documentInsertCmd)
|
|
398
|
-
documentCmd.AddCommand(documentInsertManyCmd)
|
|
399
|
-
documentCmd.AddCommand(documentQueryCmd)
|
|
400
|
-
documentCmd.AddCommand(documentGetCmd)
|
|
401
|
-
documentCmd.AddCommand(documentFindByIDsCmd)
|
|
402
|
-
documentCmd.AddCommand(documentUpdateCmd)
|
|
403
|
-
documentCmd.AddCommand(documentUpdateByQueryCmd)
|
|
404
|
-
documentCmd.AddCommand(documentDeleteCmd)
|
|
405
|
-
documentCmd.AddCommand(documentDeleteByQueryCmd)
|
|
406
|
-
documentCmd.AddCommand(documentAggregateCmd)
|
|
407
|
-
documentCmd.AddCommand(documentCountCmd)
|
|
408
|
-
rootCmd.AddCommand(documentCmd)
|
|
409
|
-
}
|
package/cli/cmd/health.go
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"github.com/nexoral/axiodb-cli/internal/config"
|
|
5
|
-
"github.com/nexoral/axiodb-cli/pkg/commands"
|
|
6
|
-
"github.com/spf13/cobra"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
var healthCmd = &cobra.Command{
|
|
10
|
-
Use: "health", Short: "Check AxioDB service health",
|
|
11
|
-
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
12
|
-
cfg, err := config.FromFlags(cmd); if err != nil { return err }
|
|
13
|
-
client, err := cfg.ConnectAndAuth(); if err != nil { return err }; defer client.Disconnect()
|
|
14
|
-
response, err := commands.Health(client); if err != nil { return err }
|
|
15
|
-
return printOutput(cfg.Output, response)
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func init() { rootCmd.AddCommand(healthCmd) }
|
package/cli/cmd/index.go
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
|
|
6
|
-
"github.com/nexoral/axiodb-cli/internal/config"
|
|
7
|
-
"github.com/nexoral/axiodb-cli/pkg/commands"
|
|
8
|
-
"github.com/spf13/cobra"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
var indexCmd = &cobra.Command{
|
|
12
|
-
Use: "index",
|
|
13
|
-
Short: "Index operations",
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
var indexCreateCmd = &cobra.Command{
|
|
17
|
-
Use: "create <field1> [field2...]",
|
|
18
|
-
Short: "Create an index on fields",
|
|
19
|
-
Args: cobra.MinimumNArgs(1),
|
|
20
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
21
|
-
cfg, err := config.FromFlags(cmd)
|
|
22
|
-
if err != nil {
|
|
23
|
-
return err
|
|
24
|
-
}
|
|
25
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
26
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
client, err := cfg.ConnectAndAuth()
|
|
30
|
-
if err != nil {
|
|
31
|
-
return err
|
|
32
|
-
}
|
|
33
|
-
defer client.Disconnect()
|
|
34
|
-
|
|
35
|
-
resp, err := commands.CreateIndex(client, cfg.DB, cfg.Collection, args)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return err
|
|
38
|
-
}
|
|
39
|
-
return printOutput(cfg.Output, resp)
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
var indexDropCmd = &cobra.Command{
|
|
44
|
-
Use: "drop <name>",
|
|
45
|
-
Short: "Drop an index by name",
|
|
46
|
-
Args: cobra.ExactArgs(1),
|
|
47
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
48
|
-
cfg, err := config.FromFlags(cmd)
|
|
49
|
-
if err != nil {
|
|
50
|
-
return err
|
|
51
|
-
}
|
|
52
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
53
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
client, err := cfg.ConnectAndAuth()
|
|
57
|
-
if err != nil {
|
|
58
|
-
return err
|
|
59
|
-
}
|
|
60
|
-
defer client.Disconnect()
|
|
61
|
-
|
|
62
|
-
resp, err := commands.DropIndex(client, cfg.DB, cfg.Collection, args[0])
|
|
63
|
-
if err != nil {
|
|
64
|
-
return err
|
|
65
|
-
}
|
|
66
|
-
return printOutput(cfg.Output, resp)
|
|
67
|
-
},
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
var indexListCmd = &cobra.Command{
|
|
71
|
-
Use: "list",
|
|
72
|
-
Short: "List all indexes on a collection",
|
|
73
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
74
|
-
cfg, err := config.FromFlags(cmd)
|
|
75
|
-
if err != nil {
|
|
76
|
-
return err
|
|
77
|
-
}
|
|
78
|
-
if cfg.DB == "" || cfg.Collection == "" {
|
|
79
|
-
return fmt.Errorf("--db and --collection flags are required")
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
client, err := cfg.ConnectAndAuth()
|
|
83
|
-
if err != nil {
|
|
84
|
-
return err
|
|
85
|
-
}
|
|
86
|
-
defer client.Disconnect()
|
|
87
|
-
|
|
88
|
-
resp, err := commands.ListIndexes(client, cfg.DB, cfg.Collection)
|
|
89
|
-
if err != nil {
|
|
90
|
-
return err
|
|
91
|
-
}
|
|
92
|
-
return printOutput(cfg.Output, resp)
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
func init() {
|
|
97
|
-
indexCmd.AddCommand(indexCreateCmd)
|
|
98
|
-
indexCmd.AddCommand(indexDropCmd)
|
|
99
|
-
indexCmd.AddCommand(indexListCmd)
|
|
100
|
-
rootCmd.AddCommand(indexCmd)
|
|
101
|
-
}
|
package/cli/cmd/ping.go
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
|
|
6
|
-
"github.com/nexoral/axiodb-cli/internal/config"
|
|
7
|
-
"github.com/spf13/cobra"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
var pingCmd = &cobra.Command{
|
|
11
|
-
Use: "ping",
|
|
12
|
-
Short: "Test connection to AxioDB server",
|
|
13
|
-
RunE: func(cmd *cobra.Command, args []string) error {
|
|
14
|
-
cfg, err := config.FromFlags(cmd)
|
|
15
|
-
if err != nil {
|
|
16
|
-
return err
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
client, err := cfg.ConnectAndAuth()
|
|
20
|
-
if err != nil {
|
|
21
|
-
return err
|
|
22
|
-
}
|
|
23
|
-
defer client.Disconnect()
|
|
24
|
-
|
|
25
|
-
if err := client.Ping(); err != nil {
|
|
26
|
-
return fmt.Errorf("ping failed: %w", err)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fmt.Println("PONG")
|
|
30
|
-
return nil
|
|
31
|
-
},
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
func init() {
|
|
35
|
-
rootCmd.AddCommand(pingCmd)
|
|
36
|
-
}
|
package/cli/cmd/root.go
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"os"
|
|
6
|
-
|
|
7
|
-
"github.com/spf13/cobra"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
var rootCmd = &cobra.Command{
|
|
11
|
-
Use: "axiodb",
|
|
12
|
-
Short: "AxioDB CLI - Connect to AxioDB via TCP protocol",
|
|
13
|
-
Long: `AxioDB CLI provides a command-line interface to interact with AxioDB database servers using the TCP protocol.`,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
func Execute() {
|
|
17
|
-
if err := rootCmd.Execute(); err != nil {
|
|
18
|
-
fmt.Fprintln(os.Stderr, err)
|
|
19
|
-
os.Exit(1)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
func init() {
|
|
24
|
-
rootCmd.PersistentFlags().StringP("connection-string", "c", "", "Connection string (axiodb://host:port)")
|
|
25
|
-
rootCmd.PersistentFlags().String("host", "localhost", "Server host")
|
|
26
|
-
rootCmd.PersistentFlags().Int("port", 27019, "Server port")
|
|
27
|
-
rootCmd.PersistentFlags().StringP("username", "u", "", "Username for authentication")
|
|
28
|
-
rootCmd.PersistentFlags().StringP("password", "p", "", "Password for authentication")
|
|
29
|
-
rootCmd.PersistentFlags().Bool("tls", false, "Enable TLS")
|
|
30
|
-
rootCmd.PersistentFlags().String("tls-cert", "", "Path to CA certificate")
|
|
31
|
-
rootCmd.PersistentFlags().Bool("tls-skip-verify", false, "Skip TLS certificate verification")
|
|
32
|
-
rootCmd.PersistentFlags().StringP("output", "o", "table", "Output format: json|table")
|
|
33
|
-
rootCmd.PersistentFlags().Int("timeout", 30, "Request timeout in seconds")
|
|
34
|
-
rootCmd.PersistentFlags().String("db", "", "Database name")
|
|
35
|
-
rootCmd.PersistentFlags().String("collection", "", "Collection name")
|
|
36
|
-
rootCmd.PersistentFlags().String("http-host", "localhost", "HTTP server host (for export/import)")
|
|
37
|
-
rootCmd.PersistentFlags().Int("http-port", 27018, "HTTP server port (for export/import)")
|
|
38
|
-
}
|