Skip to content

Commit

Permalink
Merge pull request #16 from Amar-C/master
Browse files Browse the repository at this point in the history
Improve Exception Handling
  • Loading branch information
thotasrinath authored Sep 11, 2024
2 parents c644a30 + b6d66aa commit 6066efd
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions couchbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package xk6_couchbase

import (
"fmt"
"log"
"time"

"github.com/couchbase/gocb/v2"
Expand All @@ -28,7 +27,6 @@ func (*CouchBase) NewClient(connectionString, username, password string) interfa
},
})
if err != nil {
log.Fatal(err)
return err
}

Expand All @@ -39,13 +37,11 @@ func (c *Client) Insert(bucketName, scope, collection, docId string, doc any) er
bucket := c.client.Bucket(bucketName)
err := bucket.WaitUntilReady(5*time.Second, nil)
if err != nil {
log.Fatal(err)
return err
}
col := bucket.Scope(scope).Collection(collection)
_, err = col.Insert(docId, doc, nil)
if err != nil {
log.Fatal(err)
return err
}
return nil
Expand All @@ -55,13 +51,11 @@ func (c *Client) Upsert(bucketName, scope, collection, docId string, doc any) er
bucket := c.client.Bucket(bucketName)
err := bucket.WaitUntilReady(5*time.Second, nil)
if err != nil {
log.Fatal(err)
return err
}
col := bucket.Scope(scope).Collection(collection)
_, err = col.Upsert(docId, doc, nil)
if err != nil {
log.Fatal(err)
return err
}
return nil
Expand All @@ -71,7 +65,6 @@ func (c *Client) Remove(bucketName, scope, collection, docId string) error {
bucket := c.client.Bucket(bucketName)
err := bucket.WaitUntilReady(5*time.Second, nil)
if err != nil {
log.Fatal(err)
return err
}

Expand All @@ -83,10 +76,6 @@ func (c *Client) Remove(bucketName, scope, collection, docId string) error {
DurabilityLevel: gocb.DurabilityLevelMajority,
})
if err != nil {
panic(err)
}
if err != nil {
log.Fatal(err)
return err
}
return nil
Expand All @@ -103,13 +92,11 @@ func (c *Client) InsertBatch(bucketName, scope, collection string, docs map[stri
bucket := c.client.Bucket(bucketName)
err := bucket.WaitUntilReady(5*time.Second, nil)
if err != nil {
log.Fatal(err)
return err
}
col := bucket.Scope(scope).Collection(collection)
err = col.Do(batchItems, &gocb.BulkOpOptions{Timeout: 3 * time.Second})
if err != nil {
log.Fatal(err)
return err
}

Expand All @@ -124,15 +111,13 @@ func (c *Client) Find(query string) (any, error) {
&gocb.QueryOptions{},
)
if err != nil {
log.Fatal(err)
return result, err
}
// Print each found Row
for queryResult.Next() {

err := queryResult.Row(&result)
if err != nil {
log.Fatal(err)
return result, err
}
}
Expand All @@ -145,20 +130,17 @@ func (c *Client) FindOne(bucketName, scope, collection, docId string) (any, erro
bucket := c.client.Bucket(bucketName)
err := bucket.WaitUntilReady(5*time.Second, nil)
if err != nil {
log.Fatal(err)
return result, err
}
bucketScope := bucket.Scope(scope)

getResult, err := bucketScope.Collection(collection).Get(docId, nil)
if err != nil {
log.Fatal(err)
return result, err
}

err = getResult.Content(&result)
if err != nil {
log.Fatal(err)
return result, err
}

Expand All @@ -175,15 +157,13 @@ func (c *Client) FindByPreparedStmt(query string, params ...interface{}) (any, e
},
)
if err != nil {
log.Fatal(err)
return result, err
}
// Print each found Row
for queryResult.Next() {

err := queryResult.Row(&result)
if err != nil {
log.Fatal(err)
return result, err
}
}
Expand Down

0 comments on commit 6066efd

Please sign in to comment.