Skip to content

Commit

Permalink
add URL support for sqlitedata
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Mar 28, 2018
1 parent 9d9b284 commit 70fa600
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Sources/SQLite/Data/SQLiteData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extension SQLiteData: CustomStringConvertible {
public var description: String {
switch self {
case .blob(let data):
return data.description
return String(data: data, encoding: .utf8) ?? data.hexDebug
case .float(let float):
return float.description
case .integer(let int):
Expand Down Expand Up @@ -162,6 +162,26 @@ extension String: SQLiteDataConvertible {
}
}

extension URL: SQLiteDataConvertible {
/// See `SQLiteDataConvertible.convertFromSQLiteData(_:)`
public static func convertFromSQLiteData(_ data: SQLiteData) throws -> URL {
switch data {
case .text(let string):
guard let url = URL(string: string) else {
throw SQLiteError(problem: .warning, reason: "Could not convert to URL: \(data)", source: .capture())
}
return url
default: throw SQLiteError(problem: .warning, reason: "Could not convert to URL: \(data)", source: .capture())
}
}

/// See `convertToSQLiteData()`
public func convertToSQLiteData() throws -> SQLiteData {
return .text(description)
}
}


extension FixedWidthInteger {
/// See `SQLiteDataConvertible.convertFromSQLiteData(_:)`
public static func convertFromSQLiteData(_ data: SQLiteData) throws -> Self {
Expand Down

0 comments on commit 70fa600

Please sign in to comment.