Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

publicize row properties #14

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/MySQLNIO/MySQLQueryCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ private final class MySQLQueryCommand: MySQLCommand {
}

let data = try MySQLProtocol.BinaryResultSetRow.decode(from: &packet, columns: columns)
let row = MySQLRow(format: .binary, columns: self.columns, values: data.values)
let row = MySQLRow(
format: .binary,
columnDefinitions: self.columns,
values: data.values
)
do {
try self.onRow(row)
} catch {
Expand Down
16 changes: 8 additions & 8 deletions Sources/MySQLNIO/MySQLRow.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
public struct MySQLRow: CustomStringConvertible {
private let columns: [MySQLProtocol.ColumnDefinition41]
private let values: [ByteBuffer?]
private let format: MySQLData.Format
public let format: MySQLData.Format
public let columnDefinitions: [MySQLProtocol.ColumnDefinition41]
public let values: [ByteBuffer?]

public var description: String {
var desc = [String: MySQLData]()
for (column, value) in zip(self.columns, self.values) {
for (column, value) in zip(self.columnDefinitions, self.values) {
desc[column.name] = .init(
type: column.columnType,
format: self.format,
Expand All @@ -16,18 +16,18 @@ public struct MySQLRow: CustomStringConvertible {
return desc.description
}

init(
public init(
format: MySQLData.Format,
columns: [MySQLProtocol.ColumnDefinition41],
columnDefinitions: [MySQLProtocol.ColumnDefinition41],
values: [ByteBuffer?]
) {
self.format = format
self.columns = columns
self.columnDefinitions = columnDefinitions
self.values = values
}

public func column(_ name: String, table: String? = nil) -> MySQLData? {
for (column, value) in zip(self.columns, self.values) {
for (column, value) in zip(self.columnDefinitions, self.values) {
if column.name == name && (table == nil || column.table == table) {
return .init(
type: column.columnType,
Expand Down
6 changes: 5 additions & 1 deletion Sources/MySQLNIO/MySQLSimpleQueryCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ private final class MySQLSimpleQueryCommand: MySQLCommand {
}

let data = try MySQLProtocol.TextResultSetRow.decode(from: &packet, columnCount: columns.count)
let row = MySQLRow(format: .text, columns: self.columns, values: data.values)
let row = MySQLRow(
format: .text,
columnDefinitions: self.columns,
values: data.values
)
self.onRow(row)
return .noResponse
case .done: fatalError()
Expand Down