Commit 96c4059
authored
Add functions to retrieve C* column names (#71)
Provide a way to retrieve C* column names from a query result
### Motivation:
- The underlying DataStax C++ driver already exposes column names via
cass_result_column_name()
- The Swift library already supports accessing columns by name via
row.column(_ name: String)
- However, there's no way to discover what column names are available in
a result set
- This is essential for building dynamic query tools, debug utilities,
or any application that needs to work with unknown schemas at compile
time
### Modifications:
2 new functions:
- columnName(at index: Int) -> String? - Returns the column name for a
given column index
- columnNames() -> [String] - Returns an array of all column names in
the result set
### Result:
Use case example:
```
let rows = try await session.query("SELECT * FROM system_schema.tables", on: eventLoop)
let columnNames = rows.columnNames() // ["keyspace_name", "table_name", "id", ...]
for row in rows {
for (index, columnName) in columnNames.enumerated() {
if let column = row.column(index) {
print("\(columnName): \(column.string ?? "<null>")")
}
}
}
```1 parent 08b45f6 commit 96c4059
File tree
2 files changed
+108
-0
lines changed- Sources/CassandraClient
- Tests/CassandraClientTests
2 files changed
+108
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
47 | 77 | | |
48 | 78 | | |
49 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1118 | 1118 | | |
1119 | 1119 | | |
1120 | 1120 | | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1121 | 1199 | | |
1122 | 1200 | | |
1123 | 1201 | | |
| |||
0 commit comments