Skip to content

Commit

Permalink
Merge pull request #36 from Adarsh-jaiss/main
Browse files Browse the repository at this point in the history
Added docs for CLI
  • Loading branch information
tqindia authored May 28, 2024
2 parents e7a9860 + 91db341 commit e778f48
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go get github.com/thesaas-company/xray@latest
- [BigQuery](./example/bigquery/README.md)
- [snowflake](./example/snowflake/README.md)
- [mssql](./example/mssql/README.md)
- CLI Docs : [Getting started](./cli/README.md)

### Install xRay cli

Expand Down
111 changes: 111 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Interact with Xray using Xray-CLI

To execute commands in SQL databases directly from shell you can use different configs for different databases and warehouses.
The CLI supports Mysql, Postgres, Microsoft SQL Server, Snowflake, Bigquery and Redhsift.

Simply run this command : `xray` to see all the commands in the CLI application.
If you need more info about a specific command, you can run this : `xray <COMMAND> --help`.
For example: Currently we only support shell command, which is used for interacting with different SQL databases. you can see the available options or more info via this command : `xray shell --help` or `xray shell -h`. you can use this command to see the available flags and their use case.

To execute query in any database, use this command :

```
xray shell -t <DATABASE TYPE> -c <Config.yaml file location>
```

if you want the result in verbose mode, you can add the -v flag in the command as well

```
xray shell -t <DATABASE TYPE> -c <Config.yaml file location> -v
```


### Mysql

To run mysql and interact with it, simply run this command :

<!-- Export DB_PASSWORD=YOURPASSWORD -->

```
xray shell -t mysql -c example/mysql/config.yaml
```

For verbose mode :
```
xray shell -t mysql -c example/mysql/config.yaml -v
```

### Postgres

To run postgres and interact with it, simply run this command :

<!-- Export DB_PASSWORD=YOURPASSWORD -->

```
xray shell -t postgres -c example/postgres/config.yaml
```

For verbose mode :
```
xray shell -t postgres -c example/postgres/config.yaml -v
```

### MSSQL

To run mssql and interact with it, simply run this command :

<!-- Export DB_PASSWORD=YOURPASSWORD -->

```
xray shell -t mssql -c example/mssql/config.yaml
```

For verbose mode :
```
xray shell -t mssql -c example/mssql/config.yaml -v
```

### Snowflake

To run snowflake and interact with it, simply run this command :

<!-- Export DB_PASSWORD=YOURPASSWORD -->

```
xray shell -t snowflake -c example/snowflake/config.yaml
```

For verbose mode :
```
xray shell -t snowflake -c example/snowflake/config.yaml -v
```

### Redhshift

To run redshift and interact with it, simply run this command :

<!-- export DB_PASSWORD=YOURPASSWORD -->

```
xray shell -t redshift -c example/redshift/config.yaml
```

For verbose mode :
```
xray shell -t redshift -c example/redshift/config.yaml -v
```

### Bigquery

To run bigquery and interact with it, simply run this command :

<!-- export GOOGLE_APPLICATION_CREDENTIALS=path/to/secret.json-->

```
xray shell -t bigquery -c example/bigquery/config.yaml
```

For verbose mode :
```
xray shell -t bigquery -c example/bigquery/config.yaml -v
```
197 changes: 197 additions & 0 deletions databases/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"database/sql"
"encoding/json"
"fmt"
"reflect"
"regexp"
"testing"

"github.com/DATA-DOG/go-sqlmock"
_ "github.com/go-sql-driver/mysql"
"github.com/thesaas-company/xray/config"
"github.com/thesaas-company/xray/types"
)

Expand Down Expand Up @@ -185,3 +188,197 @@ func TestGenerateCreateTablequery(t *testing.T) {
}

}

func TestNewMySQL(t *testing.T) {
type args struct {
dbClient *sql.DB
}
tests := []struct {
name string
args args
want types.ISQL
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewMySQL(tt.args.dbClient)
if (err != nil) != tt.wantErr {
t.Errorf("NewMySQL() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewMySQL() = %v, want %v", got, tt.want)
}
})
}
}

func TestNewMySQLWithConfig(t *testing.T) {
type args struct {
dbConfig *config.Config
}
tests := []struct {
name string
args args
want types.ISQL
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewMySQLWithConfig(tt.args.dbConfig)
if (err != nil) != tt.wantErr {
t.Errorf("NewMySQLWithConfig() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewMySQLWithConfig() = %v, want %v", got, tt.want)
}
})
}
}

func TestMySQL_Schema(t *testing.T) {
type args struct {
table string
}
tests := []struct {
name string
m *MySQL
args args
want types.Table
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.m.Schema(tt.args.table)
if (err != nil) != tt.wantErr {
t.Errorf("MySQL.Schema() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("MySQL.Schema() = %v, want %v", got, tt.want)
}
})
}
}

func TestMySQL_Execute(t *testing.T) {
type args struct {
query string
}
tests := []struct {
name string
m *MySQL
args args
want []byte
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.m.Execute(tt.args.query)
if (err != nil) != tt.wantErr {
t.Errorf("MySQL.Execute() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("MySQL.Execute() = %v, want %v", got, tt.want)
}
})
}
}

func TestMySQL_Tables(t *testing.T) {
type args struct {
databaseName string
}
tests := []struct {
name string
m *MySQL
args args
want []string
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.m.Tables(tt.args.databaseName)
if (err != nil) != tt.wantErr {
t.Errorf("MySQL.Tables() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("MySQL.Tables() = %v, want %v", got, tt.want)
}
})
}
}

func TestMySQL_GenerateCreateTableQuery(t *testing.T) {
type args struct {
table types.Table
}
tests := []struct {
name string
m *MySQL
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.m.GenerateCreateTableQuery(tt.args.table); got != tt.want {
t.Errorf("MySQL.GenerateCreateTableQuery() = %v, want %v", got, tt.want)
}
})
}
}

func Test_convertTypeToMysql(t *testing.T) {
type args struct {
dataType string
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertTypeToMysql(tt.args.dataType); got != tt.want {
t.Errorf("convertTypeToMysql() = %v, want %v", got, tt.want)
}
})
}
}

func Test_dbURLMySQL(t *testing.T) {
type args struct {
dbConfig *config.Config
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := dbURLMySQL(tt.args.dbConfig); got != tt.want {
t.Errorf("dbURLMySQL() = %v, want %v", got, tt.want)
}
})
}
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ require (
github.com/aws/smithy-go v1.14.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/elgs/gosqlcrud v0.0.0-20240405131937-de90abf1755a // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-logr/logr v1.4.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/elgs/gosqlcrud v0.0.0-20240405131937-de90abf1755a h1:5fRodZBvUatkP8rF+eM0mnWfzQnsX4soUNBKpqmH+g8=
github.com/elgs/gosqlcrud v0.0.0-20240405131937-de90abf1755a/go.mod h1:1aQxDp0l1rY6JkTM6mhgsV0c3hfow5WlfWIaoeydhWc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down

0 comments on commit e778f48

Please sign in to comment.