@@ -42,7 +42,7 @@ func dereference(i interface{}) interface{} {
4242 return reflect .Indirect (reflect .ValueOf (i )).Interface ()
4343}
4444
45- // TupeColumnName will return the column name of a tuple value in a column named
45+ // TupleColumnName will return the column name of a tuple value in a column named
4646// c at index n. It should be used if a specific element within a tuple is needed
4747// to be extracted from a map returned from SliceMap or MapScan.
4848func TupleColumnName (c string , n int ) string {
@@ -81,8 +81,60 @@ func (iter *Iter) RowData() (RowData, error) {
8181 return rowData , nil
8282}
8383
84- // SliceMap is a helper function to make the API easier to use
85- // returns the data from the query in the form of []map[string]interface{}
84+ // SliceMap is a helper function to make the API easier to use.
85+ // It returns the data from the query in the form of []map[string]interface{}.
86+ //
87+ // Columns are automatically converted to Go types based on their CQL type.
88+ // The following table shows exactly what Go type to expect when accessing map values:
89+ //
90+ // CQL Type | Go Type (Non-NULL) | Go Value for NULL | Type Assertion Example
91+ // ascii | string | "" | row["col"].(string)
92+ // bigint | int64 | int64(0) | row["col"].(int64)
93+ // blob | []byte | []byte(nil) | row["col"].([]byte)
94+ // boolean | bool | false | row["col"].(bool)
95+ // counter | int64 | int64(0) | row["col"].(int64)
96+ // date | time.Time | time.Time{} | row["col"].(time.Time)
97+ // decimal | *inf.Dec | (*inf.Dec)(nil) | row["col"].(*inf.Dec)
98+ // double | float64 | float64(0) | row["col"].(float64)
99+ // duration | gocql.Duration | gocql.Duration{} | row["col"].(gocql.Duration)
100+ // float | float32 | float32(0) | row["col"].(float32)
101+ // inet | net.IP | net.IP(nil) | row["col"].(net.IP)
102+ // int | int | int(0) | row["col"].(int)
103+ // list<T> | []T | []T(nil) | row["col"].([]string)
104+ // map<K,V> | map[K]V | map[K]V(nil) | row["col"].(map[string]int)
105+ // set<T> | []T | []T(nil) | row["col"].([]int)
106+ // smallint | int16 | int16(0) | row["col"].(int16)
107+ // text | string | "" | row["col"].(string)
108+ // time | time.Duration | time.Duration(0) | row["col"].(time.Duration)
109+ // timestamp | time.Time | time.Time{} | row["col"].(time.Time)
110+ // timeuuid | gocql.UUID | gocql.UUID{} | row["col"].(gocql.UUID)
111+ // tinyint | int8 | int8(0) | row["col"].(int8)
112+ // tuple<T1,T2,...> | (see below) | (see below) | (see below)
113+ // uuid | gocql.UUID | gocql.UUID{} | row["col"].(gocql.UUID)
114+ // varchar | string | "" | row["col"].(string)
115+ // varint | *big.Int | (*big.Int)(nil) | row["col"].(*big.Int)
116+ // vector<T,N> | []T | []T(nil) | row["col"].([]float32)
117+ //
118+ // Special Cases:
119+ //
120+ // Tuple Types: Tuple elements are split into separate map entries with keys like "column[0]", "column[1]", etc.
121+ // Use TupleColumnName to generate the correct key:
122+ //
123+ // // For tuple<int, text> column named "my_tuple"
124+ // elem0 := row[gocql.TupleColumnName("my_tuple", 0)].(int)
125+ // elem1 := row[gocql.TupleColumnName("my_tuple", 1)].(string)
126+ //
127+ // User-Defined Types (UDTs): Returned as map[string]interface{} with field names as keys:
128+ //
129+ // udt := row["my_udt"].(map[string]interface{})
130+ // name := udt["name"].(string)
131+ // age := udt["age"].(int)
132+ //
133+ // Important Notes:
134+ // - Always use type assertions when accessing map values: row["col"].(ExpectedType)
135+ // - NULL database values return Go zero values or nil for pointer types
136+ // - Collection types (list, set, map, vector) return nil slices/maps for NULL values
137+ // - Migration from v1.x: inet columns now return net.IP instead of string values
86138func (iter * Iter ) SliceMap () ([]map [string ]interface {}, error ) {
87139 if iter .err != nil {
88140 return nil , iter .err
@@ -104,11 +156,16 @@ func (iter *Iter) SliceMap() ([]map[string]interface{}, error) {
104156}
105157
106158// MapScan takes a map[string]interface{} and populates it with a row
107- // that is returned from cassandra .
159+ // that is returned from Cassandra .
108160//
109161// Each call to MapScan() must be called with a new map object.
110162// During the call to MapScan() any pointers in the existing map
111- // are replaced with non pointer types before the call returns
163+ // are replaced with non pointer types before the call returns.
164+ //
165+ // Columns are automatically converted to Go types based on their CQL type.
166+ // See SliceMap for the complete CQL to Go type mapping table and examples.
167+ //
168+ // Usage Examples:
112169//
113170// iter := session.Query(`SELECT * FROM mytable`).Iter()
114171// for {
@@ -123,7 +180,7 @@ func (iter *Iter) SliceMap() ([]map[string]interface{}, error) {
123180// }
124181// }
125182//
126- // You can also pass pointers in the map before each call
183+ // You can also pass pointers in the map before each call:
127184//
128185// var fullName FullName // Implements gocql.Unmarshaler and gocql.Marshaler interfaces
129186// var address net.IP
0 commit comments