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.
@@ -1,191 +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 transactionCmd = &cobra.Command{
14
- Use: "transaction",
15
- Short: "Run ACID transaction operations",
16
- Long: "ACID transactions over TCP (port 27019). Requires TCP server enabled (AXIODB_TCP=true). Use 'transaction run' for file-based batch, or begin/commit/rollback/savepoint for manual control.",
17
- }
18
-
19
- var transactionRunCmd = &cobra.Command{
20
- Use: "run <operations-json-file>",
21
- Short: "Run a transaction from a JSON operation list",
22
- Long: "Run a full transaction from a JSON file. Requires TCP (AXIODB_TCP=true) and --db/--collection. Auto-commits on success, auto-rollbacks on failure.",
23
- Args: cobra.ExactArgs(1),
24
- RunE: func(cmd *cobra.Command, args []string) error {
25
- cfg, err := config.FromFlags(cmd)
26
- if err != nil {
27
- return err
28
- }
29
- if cfg.DB == "" || cfg.Collection == "" {
30
- return fmt.Errorf("--db and --collection flags are required")
31
- }
32
- content, err := os.ReadFile(args[0])
33
- if err != nil {
34
- return fmt.Errorf("read transaction file: %w", err)
35
- }
36
- var steps []commands.TransactionStep
37
- if err := json.Unmarshal(content, &steps); err != nil {
38
- return fmt.Errorf("invalid transaction JSON: %w", err)
39
- }
40
- client, err := cfg.ConnectAndAuth()
41
- if err != nil {
42
- return err
43
- }
44
- defer client.Disconnect()
45
- response, err := commands.RunTransaction(client, cfg.DB, cfg.Collection, steps)
46
- if err != nil {
47
- return err
48
- }
49
- return printOutput(cfg.Output, response)
50
- },
51
- }
52
-
53
- var transactionBeginCmd = &cobra.Command{
54
- Use: "begin",
55
- Short: "Begin a transaction (returns transactionId)",
56
- Long: "Begin a transaction on --db/--collection. Requires TCP. Returns transactionId for subsequent commit/rollback/savepoint calls.",
57
- RunE: func(cmd *cobra.Command, args []string) error {
58
- cfg, err := config.FromFlags(cmd)
59
- if err != nil {
60
- return err
61
- }
62
- if cfg.DB == "" || cfg.Collection == "" {
63
- return fmt.Errorf("--db and --collection flags are required")
64
- }
65
- client, err := cfg.ConnectAndAuth()
66
- if err != nil {
67
- return err
68
- }
69
- defer client.Disconnect()
70
- resp, err := commands.BeginTransaction(client, cfg.DB, cfg.Collection)
71
- if err != nil {
72
- return err
73
- }
74
- return printOutput(cfg.Output, resp)
75
- },
76
- }
77
-
78
- var transactionCommitCmd = &cobra.Command{
79
- Use: "commit <transactionId>",
80
- Short: "Commit a transaction",
81
- Args: cobra.ExactArgs(1),
82
- RunE: func(cmd *cobra.Command, args []string) error {
83
- cfg, err := config.FromFlags(cmd)
84
- if err != nil {
85
- return err
86
- }
87
- client, err := cfg.ConnectAndAuth()
88
- if err != nil {
89
- return err
90
- }
91
- defer client.Disconnect()
92
- resp, err := commands.CommitTransaction(client, args[0])
93
- if err != nil {
94
- return err
95
- }
96
- return printOutput(cfg.Output, resp)
97
- },
98
- }
99
-
100
- var transactionRollbackCmd = &cobra.Command{
101
- Use: "rollback <transactionId>",
102
- Short: "Rollback a transaction",
103
- Args: cobra.ExactArgs(1),
104
- RunE: func(cmd *cobra.Command, args []string) error {
105
- cfg, err := config.FromFlags(cmd)
106
- if err != nil {
107
- return err
108
- }
109
- client, err := cfg.ConnectAndAuth()
110
- if err != nil {
111
- return err
112
- }
113
- defer client.Disconnect()
114
- resp, err := commands.RollbackTransaction(client, args[0])
115
- if err != nil {
116
- return err
117
- }
118
- return printOutput(cfg.Output, resp)
119
- },
120
- }
121
-
122
- var transactionSavepointCmd = &cobra.Command{
123
- Use: "savepoint <transactionId> <name>",
124
- Short: "Create a savepoint",
125
- Args: cobra.ExactArgs(2),
126
- RunE: func(cmd *cobra.Command, args []string) error {
127
- cfg, err := config.FromFlags(cmd)
128
- if err != nil {
129
- return err
130
- }
131
- client, err := cfg.ConnectAndAuth()
132
- if err != nil {
133
- return err
134
- }
135
- defer client.Disconnect()
136
- resp, err := commands.Savepoint(client, args[0], args[1])
137
- if err != nil {
138
- return err
139
- }
140
- return printOutput(cfg.Output, resp)
141
- },
142
- }
143
-
144
- var transactionRollbackToCmd = &cobra.Command{
145
- Use: "rollback-to <transactionId> <name>",
146
- Short: "Rollback to a savepoint",
147
- Args: cobra.ExactArgs(2),
148
- RunE: func(cmd *cobra.Command, args []string) error {
149
- cfg, err := config.FromFlags(cmd)
150
- if err != nil {
151
- return err
152
- }
153
- client, err := cfg.ConnectAndAuth()
154
- if err != nil {
155
- return err
156
- }
157
- defer client.Disconnect()
158
- resp, err := commands.RollbackToSavepoint(client, args[0], args[1])
159
- if err != nil {
160
- return err
161
- }
162
- return printOutput(cfg.Output, resp)
163
- },
164
- }
165
-
166
- var transactionReleaseCmd = &cobra.Command{
167
- Use: "release <transactionId> <name>",
168
- Short: "Release a savepoint",
169
- Args: cobra.ExactArgs(2),
170
- RunE: func(cmd *cobra.Command, args []string) error {
171
- cfg, err := config.FromFlags(cmd)
172
- if err != nil {
173
- return err
174
- }
175
- client, err := cfg.ConnectAndAuth()
176
- if err != nil {
177
- return err
178
- }
179
- defer client.Disconnect()
180
- resp, err := commands.ReleaseSavepoint(client, args[0], args[1])
181
- if err != nil {
182
- return err
183
- }
184
- return printOutput(cfg.Output, resp)
185
- },
186
- }
187
-
188
- func init() {
189
- transactionCmd.AddCommand(transactionRunCmd, transactionBeginCmd, transactionCommitCmd, transactionRollbackCmd, transactionSavepointCmd, transactionRollbackToCmd, transactionReleaseCmd)
190
- rootCmd.AddCommand(transactionCmd)
191
- }
@@ -1,27 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "fmt"
5
-
6
- "github.com/spf13/cobra"
7
- )
8
-
9
- var cliVersion = "20.3.2"
10
-
11
- var versionCmd = &cobra.Command{
12
- Use: "version",
13
- Short: "Print the CLI version",
14
- Run: func(cmd *cobra.Command, args []string) {
15
- short, _ := cmd.Flags().GetBool("short")
16
- if short {
17
- fmt.Println(cliVersion)
18
- } else {
19
- fmt.Printf("axiodb-cli version %s\n", cliVersion)
20
- }
21
- },
22
- }
23
-
24
- func init() {
25
- versionCmd.Flags().Bool("short", false, "Print only the version number")
26
- rootCmd.AddCommand(versionCmd)
27
- }
package/cli/go.mod DELETED
@@ -1,15 +0,0 @@
1
- module github.com/nexoral/axiodb-cli
2
-
3
- go 1.22
4
-
5
- require (
6
- github.com/chzyer/readline v1.5.1
7
- github.com/google/uuid v1.6.0
8
- github.com/spf13/cobra v1.8.1
9
- )
10
-
11
- require (
12
- github.com/inconshreveable/mousetrap v1.1.0 // indirect
13
- github.com/spf13/pflag v1.0.5 // indirect
14
- golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
15
- )
package/cli/go.sum DELETED
@@ -1,20 +0,0 @@
1
- github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
2
- github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
3
- github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
4
- github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
5
- github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
6
- github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
7
- github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
8
- github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
9
- github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
10
- github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
11
- github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
12
- github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
13
- github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
14
- github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
15
- github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
16
- github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
17
- golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
18
- golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
19
- gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
20
- gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@@ -1,120 +0,0 @@
1
- package config
2
-
3
- import (
4
- "fmt"
5
- "strconv"
6
- "strings"
7
- "time"
8
-
9
- "github.com/nexoral/axiodb-cli/pkg/httpclient"
10
- "github.com/nexoral/axiodb-cli/pkg/protocol"
11
- "github.com/spf13/cobra"
12
- )
13
-
14
- type Config struct {
15
- Host string
16
- Port int
17
- ConnString string
18
- Username string
19
- Password string
20
- TLSEnabled bool
21
- TLSCertPath string
22
- TLSSkipVerify bool
23
- Output string
24
- Timeout int
25
- DB string
26
- Collection string
27
- HTTPHost string
28
- HTTPPort int
29
- }
30
-
31
- func FromFlags(cmd *cobra.Command) (*Config, error) {
32
- cfg := &Config{}
33
-
34
- cfg.Host, _ = cmd.Flags().GetString("host")
35
- cfg.Port, _ = cmd.Flags().GetInt("port")
36
- cfg.ConnString, _ = cmd.Flags().GetString("connection-string")
37
- cfg.Username, _ = cmd.Flags().GetString("username")
38
- cfg.Password, _ = cmd.Flags().GetString("password")
39
- cfg.TLSEnabled, _ = cmd.Flags().GetBool("tls")
40
- cfg.TLSCertPath, _ = cmd.Flags().GetString("tls-cert")
41
- cfg.TLSSkipVerify, _ = cmd.Flags().GetBool("tls-skip-verify")
42
- cfg.Output, _ = cmd.Flags().GetString("output")
43
- cfg.Timeout, _ = cmd.Flags().GetInt("timeout")
44
- cfg.DB, _ = cmd.Flags().GetString("db")
45
- cfg.Collection, _ = cmd.Flags().GetString("collection")
46
- cfg.HTTPHost, _ = cmd.Flags().GetString("http-host")
47
- cfg.HTTPPort, _ = cmd.Flags().GetInt("http-port")
48
-
49
- if cfg.ConnString != "" {
50
- host, port, err := parseConnectionString(cfg.ConnString)
51
- if err != nil {
52
- return nil, err
53
- }
54
- cfg.Host = host
55
- cfg.Port = port
56
- }
57
-
58
- return cfg, nil
59
- }
60
-
61
- func parseConnectionString(connStr string) (string, int, error) {
62
- if !strings.HasPrefix(connStr, "axiodb://") {
63
- return "", 0, fmt.Errorf("invalid connection string format (expected axiodb://host:port): %s", connStr)
64
- }
65
-
66
- hostPort := strings.TrimPrefix(connStr, "axiodb://")
67
- parts := strings.SplitN(hostPort, ":", 2)
68
- if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
69
- return "", 0, fmt.Errorf("invalid connection string format (expected axiodb://host:port): %s", connStr)
70
- }
71
-
72
- port, err := strconv.Atoi(parts[1])
73
- if err != nil || port <= 0 || port > 65535 {
74
- return "", 0, fmt.Errorf("invalid port number in connection string: %s", parts[1])
75
- }
76
-
77
- return parts[0], port, nil
78
- }
79
-
80
- func (c *Config) NewClient() *protocol.Client {
81
- return protocol.NewClient(protocol.ClientConfig{
82
- Host: c.Host,
83
- Port: c.Port,
84
- TLSEnabled: c.TLSEnabled,
85
- TLSCertPath: c.TLSCertPath,
86
- TLSSkipVerify: c.TLSSkipVerify,
87
- Timeout: time.Duration(c.Timeout) * time.Second,
88
- })
89
- }
90
-
91
- func (c *Config) ConnectAndAuth() (*protocol.Client, error) {
92
- client := c.NewClient()
93
-
94
- if err := client.Connect(); err != nil {
95
- return nil, fmt.Errorf("connect: %w", err)
96
- }
97
-
98
- if c.Username != "" && c.Password != "" {
99
- if _, err := protocol.Authenticate(client, c.Username, c.Password); err != nil {
100
- _ = client.Disconnect()
101
- return nil, fmt.Errorf("auth: %w", err)
102
- }
103
- }
104
-
105
- return client, nil
106
- }
107
-
108
- func GetDBContext(cmd *cobra.Command) string {
109
- db, _ := cmd.Flags().GetString("db")
110
- return db
111
- }
112
-
113
- func GetCollectionContext(cmd *cobra.Command) string {
114
- coll, _ := cmd.Flags().GetString("collection")
115
- return coll
116
- }
117
-
118
- func (c *Config) NewHTTPClient() *httpclient.HTTPClient {
119
- return httpclient.New(c.HTTPHost, c.HTTPPort, time.Duration(c.Timeout)*time.Second)
120
- }
package/cli/main.go DELETED
@@ -1,7 +0,0 @@
1
- package main
2
-
3
- import "github.com/nexoral/axiodb-cli/cmd"
4
-
5
- func main() {
6
- cmd.Execute()
7
- }
@@ -1,68 +0,0 @@
1
- package commands
2
-
3
- import (
4
- "fmt"
5
-
6
- "github.com/nexoral/axiodb-cli/pkg/protocol"
7
- )
8
-
9
- func CreateCollection(client *protocol.Client, dbName, collectionName string) (*protocol.Response, error) {
10
- resp, err := client.Send("CREATE_COLLECTION", map[string]interface{}{
11
- "dbName": dbName,
12
- "collectionName": collectionName,
13
- })
14
- if err != nil {
15
- return nil, fmt.Errorf("create collection: %w", err)
16
- }
17
- if resp.StatusCode >= 400 {
18
- return nil, fmt.Errorf("create collection failed: %s", resp.Error)
19
- }
20
- return resp, nil
21
- }
22
-
23
- func DeleteCollection(client *protocol.Client, dbName, collectionName string) (*protocol.Response, error) {
24
- resp, err := client.Send("DELETE_COLLECTION", map[string]interface{}{
25
- "dbName": dbName,
26
- "collectionName": collectionName,
27
- })
28
- if err != nil {
29
- return nil, fmt.Errorf("delete collection: %w", err)
30
- }
31
- if resp.StatusCode >= 400 {
32
- return nil, fmt.Errorf("delete collection failed: %s", resp.Error)
33
- }
34
- return resp, nil
35
- }
36
-
37
- func CollectionExists(client *protocol.Client, dbName, collectionName string) (bool, error) {
38
- resp, err := client.Send("COLLECTION_EXISTS", map[string]interface{}{
39
- "dbName": dbName,
40
- "collectionName": collectionName,
41
- })
42
- if err != nil {
43
- return false, fmt.Errorf("check collection exists: %w", err)
44
- }
45
- if resp.StatusCode >= 400 {
46
- return false, fmt.Errorf("check collection exists failed: %s", resp.Error)
47
- }
48
- data, ok := resp.Data.(map[string]interface{})
49
- if !ok {
50
- return false, nil
51
- }
52
- exists, _ := data["exists"].(bool)
53
- return exists, nil
54
- }
55
-
56
- func GetCollectionInfo(client *protocol.Client, dbName string) (*protocol.Response, error) {
57
- resp, err := client.Send("GET_COLLECTION_INFO", map[string]interface{}{
58
- "dbName": dbName,
59
- "collectionName": "_",
60
- })
61
- if err != nil {
62
- return nil, fmt.Errorf("get collection info: %w", err)
63
- }
64
- if resp.StatusCode >= 400 {
65
- return nil, fmt.Errorf("get collection info failed: %s", resp.Error)
66
- }
67
- return resp, nil
68
- }
@@ -1,62 +0,0 @@
1
- package commands
2
-
3
- import (
4
- "fmt"
5
-
6
- "github.com/nexoral/axiodb-cli/pkg/protocol"
7
- )
8
-
9
- func CreateDB(client *protocol.Client, dbName string) (*protocol.Response, error) {
10
- resp, err := client.Send("CREATE_DB", map[string]interface{}{
11
- "dbName": dbName,
12
- })
13
- if err != nil {
14
- return nil, fmt.Errorf("create database: %w", err)
15
- }
16
- if resp.StatusCode >= 400 {
17
- return nil, fmt.Errorf("create database failed: %s", resp.Error)
18
- }
19
- return resp, nil
20
- }
21
-
22
- func DeleteDB(client *protocol.Client, dbName string) (*protocol.Response, error) {
23
- resp, err := client.Send("DELETE_DB", map[string]interface{}{
24
- "dbName": dbName,
25
- })
26
- if err != nil {
27
- return nil, fmt.Errorf("delete database: %w", err)
28
- }
29
- if resp.StatusCode >= 400 {
30
- return nil, fmt.Errorf("delete database failed: %s", resp.Error)
31
- }
32
- return resp, nil
33
- }
34
-
35
- func DBExists(client *protocol.Client, dbName string) (bool, error) {
36
- resp, err := client.Send("DB_EXISTS", map[string]interface{}{
37
- "dbName": dbName,
38
- })
39
- if err != nil {
40
- return false, fmt.Errorf("check database exists: %w", err)
41
- }
42
- if resp.StatusCode >= 400 {
43
- return false, fmt.Errorf("check database exists failed: %s", resp.Error)
44
- }
45
- data, ok := resp.Data.(map[string]interface{})
46
- if !ok {
47
- return false, nil
48
- }
49
- exists, _ := data["exists"].(bool)
50
- return exists, nil
51
- }
52
-
53
- func GetInstanceInfo(client *protocol.Client) (*protocol.Response, error) {
54
- resp, err := client.Send("GET_INSTANCE_INFO", nil)
55
- if err != nil {
56
- return nil, fmt.Errorf("get instance info: %w", err)
57
- }
58
- if resp.StatusCode >= 400 {
59
- return nil, fmt.Errorf("get instance info failed: %s", resp.Error)
60
- }
61
- return resp, nil
62
- }