Skip to content

Commit

Permalink
Add limit to rows for insert command
Browse files Browse the repository at this point in the history
Signed-off-by: Shaad7 <[email protected]>
  • Loading branch information
AbdullahAlShaad authored and heheh13 committed Sep 28, 2023
1 parent f9be578 commit 2e1b05d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pkg/data/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ const (
const (
actor = "kubedb-cli"
)

const (
maxRows = 100000
)
5 changes: 2 additions & 3 deletions pkg/data/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ func InsertElasticsearchDataCMD(f cmdutil.Factory) *cobra.Command {
log.Fatalln(err)
}

if rows <= 0 {
log.Fatal("rows need to be greater than 0")
if rows < 1 || rows > maxRows {
log.Fatalf("rows need to be between 1 and %d", maxRows)
}

err = opts.insertDataInDatabase(rows)
if err != nil {
log.Fatal(err)
Expand Down
7 changes: 3 additions & 4 deletions pkg/data/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,16 @@ func InsertMariaDBDataCMD(f cmdutil.Factory) *cobra.Command {
log.Fatalln(err)
}

if rows <= 0 {
log.Fatal("Inserted rows must be greater than 0")
}

tunnel, err := lib.TunnelToDBService(opts.config, dbName, namespace, api.MySQLDatabasePort)
if err != nil {
log.Fatal("couldn't create tunnel, error: ", err)
}

defer tunnel.Close()

if rows < 1 || rows > maxRows {
log.Fatalf("rows need to be between 1 and %d", maxRows)
}
err = opts.insertDataExecCmd(tunnel, rows)
if err != nil {
log.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/data/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func InsertMongoDBDataCMD(f cmdutil.Factory) *cobra.Command {
log.Fatalln(err)
}

if rows <= 0 {
log.Fatal("rows need to be greater than 0")
if rows < 1 || rows > maxRows {
log.Fatalf("rows need to be between 1 and %d", maxRows)
}

command := fmt.Sprintf("for(var i=1;i<=%d;i++){db[\"%s\"].insert({_id:\"doc\"+i,actor:\"%s\"})}", rows, mgCollectionName, actor)
Expand Down
3 changes: 3 additions & 0 deletions pkg/data/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func InsertRedisDataCMD(f cmdutil.Factory) *cobra.Command {
if err != nil {
log.Fatalln(err)
}
if rows < 1 || rows > maxRows {
log.Fatalf("rows need to be between 1 and %d", maxRows)
}

err = opts.insertDataInDatabase(rows)
if err != nil {
Expand Down

0 comments on commit 2e1b05d

Please sign in to comment.