소스 검색

ran fmt on cassandra_test and added convenience function MapScan(map[string]interface{}) that acts like Scan()

cwandrews 12 년 전
부모
커밋
170e62b58a
2개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      cassandra_test.go
  2. 18 0
      helpers.go

+ 1 - 1
cassandra_test.go

@@ -308,7 +308,7 @@ func TestSliceMap(t *testing.T) {
 	m["testfloat"] = float32(4.564)
 	m["testdouble"] = float64(4.815162342)
 	m["testint"] = 2343
-	m["testset"] = []int{1,2,3,4,5,6,7,8,9}
+	m["testset"] = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
 	m["testmap"] = map[string]string{"field1": "val1", "field2": "val2", "field3": "val3"}
 	sliceMap := []map[string]interface{}{m}
 	if err := session.Query(`INSERT INTO slice_map_table (testuuid, testvarchar, testbigint, testblob, testbool, testfloat, testdouble, testint, testset, testmap) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,

+ 18 - 0
helpers.go

@@ -62,3 +62,21 @@ func (iter *Iter) SliceMap() ([]map[string]interface{}, error) {
 	}
 	return dataToReturn, nil
 }
+
+func (iter *Iter) MapScan(m map[string]interface{}) bool {
+	if iter.err != nil {
+		return false
+	}
+	interfacesToScan := make([]interface{}, 0)
+	for _, column := range iter.Columns() {
+		i := column.TypeInfo.New()
+		interfacesToScan = append(interfacesToScan, i)
+	}
+	if iter.Scan(interfacesToScan...) {
+		for i, column := range iter.Columns() {
+			m[column.Name] = dereference(interfacesToScan[i])
+		}
+		return true
+	}
+	return false
+}