Skip to content

Commit

Permalink
support multi-value insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
outprog committed Feb 2, 2019
1 parent 5810172 commit 45d8dc1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion kadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kadb

import (
"os"
"reflect"

"github.com/Shopify/sarama"
cluster "github.com/bsm/sarama-cluster"
Expand Down Expand Up @@ -48,7 +49,16 @@ func (k *Kadb) toDB(msg *sarama.ConsumerMessage) error {
return err
}
if dMsg != nil {
k.db.Create(dMsg)
switch reflect.TypeOf(dMsg).Kind() {
case reflect.Slice:
va := reflect.ValueOf(dMsg)
for i := 0; i < va.Len(); i++ {
value := va.Index(i)
k.db.Create(value.Interface())
}
case reflect.Ptr:
k.db.Create(dMsg)
}
}
return nil
}
Expand Down

0 comments on commit 45d8dc1

Please sign in to comment.