Skip to content
Merged
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
22 changes: 22 additions & 0 deletions Sources/PostgreSQL/Data/PostgreSQLDataCustomConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ extension PostgreSQLData: PostgreSQLDataCustomConvertible {
return self
}
}

extension RawRepresentable where RawValue: PostgreSQLDataCustomConvertible {
static var postgreSQLDataType: PostgreSQLDataType {
return Self.postgreSQLDataType
}

static var postgreSQLDataArrayType: PostgreSQLDataType {
return Self.postgreSQLDataArrayType
}

static func convertFromPostgreSQLData(_ data: PostgreSQLData) throws -> Self {
let aRawValue = try RawValue.convertFromPostgreSQLData(data)
guard let enumValue = Self(rawValue: aRawValue) else {
throw PostgreSQLError(identifier: "invalidRawValue", reason: "Unable to decode RawRepresentable from the database value.")
}
return enumValue
}

func convertToPostgreSQLData() throws -> PostgreSQLData {
return try self.rawValue.convertToPostgreSQLData()
}
}