Skip to content

Commit

Permalink
Merge pull request #467 from #463-cassandra-repo
Browse files Browse the repository at this point in the history
updated statement execute to have retry logic
  • Loading branch information
jtesser authored Mar 21, 2021
2 parents 3eb0f7e + eec06dc commit 833d5d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
8 changes: 4 additions & 4 deletions pkg/api/cassandra_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ func (r *CassandraRepository) FindAll() ([]*Definition, error) {

var savedDef string

for iter.Scan(&savedDef) {
err := iter.ScanAndClose(func() bool {
var definition *Definition
err := json.Unmarshal([]byte(savedDef), &definition)
if err != nil {
log.Errorf("error trying to unmarshal definition json: %v", err)
return nil, err
return false
}
results = append(results, definition)
}
return true
}, &savedDef)

err := iter.Close()
if err != nil {
log.Errorf("error getting all definitions: %v", err)
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/plugin/basic/cassandra_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func (r *CassandraRepository) FindAll() ([]*User, error) {
var username string
var password string

for iter.Scan(&username, &password) {
err := iter.ScanAndClose(func() bool {
var user User
user.Username = username
user.Password = password
results = append(results, &user)
}
return true
}, &username, &password)

err := iter.Close()
if err != nil {
log.Errorf("error getting all oauths: %v", err)
}
Expand All @@ -51,14 +51,11 @@ func (r *CassandraRepository) FindByUsername(username string) (*User, error) {

var user User

iter := r.session.GetSession().Query(
err := r.session.GetSession().Query(
"SELECT username, password " +
"FROM user " +
"WHERE username = ?",
username).Iter()

iter.Scan(&user.Username, &user.Password)
err := iter.Close()
username).Scan(&user.Username, &user.Password)

if err != nil {
log.Errorf("error selecting user %s: %v", username, err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/plugin/oauth2/cassandra_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ func (r *CassandraRepository) FindAll() ([]*OAuth, error) {

var savedOauth string

for iter.Scan(&savedOauth) {
err := iter.ScanAndClose(func() bool {
var oauth *OAuth
err := json.Unmarshal([]byte(savedOauth), &oauth)
if err != nil {
log.Errorf("error trying to unmarshal oauth json: %v", err)
return nil, err
return false
}
results = append(results, oauth)
}
return true
}, &savedOauth)

err := iter.Close()
if err != nil {
log.Errorf("error getting all oauths: %v", err)
}
Expand Down

0 comments on commit 833d5d9

Please sign in to comment.