forked from vapor/postgres-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgreSQLData.swift
44 lines (36 loc) · 1.16 KB
/
PostgreSQLData.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
43
44
import Foundation
/// Supported `PostgreSQLData` data types.
public struct PostgreSQLData {
/// The data's type.
public var type: PostgreSQLDataType
/// The data's format.
public var format: PostgreSQLFormatCode
/// If `true`, this data is null.
public var isNull: Bool {
return data == nil
}
/// The actual data.
public var data: Data?
public init(type: PostgreSQLDataType, format: PostgreSQLFormatCode = .binary, data: Data? = nil) {
self.type = type
self.format = format
self.data = data
}
}
extension PostgreSQLData: CustomStringConvertible {
/// See `CustomStringConvertible.description`
public var description: String {
if let data = data {
return "\(type) (\(format)) \(String(data: data, encoding: .ascii) ?? "<non-ascii>"))"
} else {
return "\(type) (\(format)) <null>"
}
}
}
/// MARK: Equatable
extension PostgreSQLData: Equatable {
/// See Equatable.==
public static func ==(lhs: PostgreSQLData, rhs: PostgreSQLData) -> Bool {
return lhs.format == rhs.format && lhs.type == rhs.type && lhs.data == rhs.data
}
}