forked from vapor/mysql-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySQLRow.swift
42 lines (39 loc) · 1.4 KB
/
MySQLRow.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public struct MySQLRow: CustomStringConvertible {
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.columnDefinitions, self.values) {
desc[column.name] = .init(
type: column.columnType,
format: self.format,
buffer: value,
isUnsigned: column.flags.contains(.COLUMN_UNSIGNED)
)
}
return desc.description
}
public init(
format: MySQLData.Format,
columnDefinitions: [MySQLProtocol.ColumnDefinition41],
values: [ByteBuffer?]
) {
self.format = format
self.columnDefinitions = columnDefinitions
self.values = values
}
public func column(_ name: String, table: String? = nil) -> MySQLData? {
for (column, value) in zip(self.columnDefinitions, self.values) {
if column.name == name && (table == nil || column.table == table) {
return .init(
type: column.columnType,
format: self.format,
buffer: value,
isUnsigned: column.flags.contains(.COLUMN_UNSIGNED)
)
}
}
return nil
}
}