Skip to content

Commit 2ce18b8

Browse files
Merge pull request #17 from Alexander-Ignition/fix-playground
2 parents e0ae99c + bce1c4d commit 2ce18b8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Sources/SQLyra/DataFrame.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension PreparedStatement {
4545
while let row = try row() {
4646
df.appendEmptyRow()
4747
for index in (0..<columnCount) {
48-
if let value = row[index] {
48+
if let value = row.value(at: index) {
4949
df.rows[count][index] = valueTransformers[index].transform(value)
5050
}
5151
}

Sources/SQLyra/PreparedStatement.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,28 @@ extension PreparedStatement {
205205
let statement: PreparedStatement
206206

207207
public subscript(dynamicMember name: String) -> Value? {
208-
self[name]
208+
value(for: name)
209209
}
210210

211211
public subscript(columnName: String) -> Value? {
212-
statement.columnIndexByName[columnName].flatMap { self[$0] }
212+
value(for: columnName)
213213
}
214214

215215
public subscript(columnIndex: Int) -> Value? {
216216
statement.value(at: columnIndex)
217217
}
218218

219+
public func value(for columnName: String) -> Value? {
220+
guard let columnIndex = statement.columnIndexByName[columnName] else {
221+
return nil
222+
}
223+
return value(at: columnIndex)
224+
}
225+
226+
public func value(at columnIndex: Int) -> Value? {
227+
statement.value(at: columnIndex)
228+
}
229+
219230
public func decode<T>(_ type: T.Type, using decoder: RowDecoder? = nil) throws -> T where T: Decodable {
220231
try (decoder ?? RowDecoder.default).decode(type, from: self)
221232
}

0 commit comments

Comments
 (0)