-
-
Notifications
You must be signed in to change notification settings - Fork 89
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
The current PostgresEncodable:
/// A type that can encode itself to a postgres wire binary representation.
public protocol PostgresEncodable {
// TODO: Rename to `PostgresThrowingEncodable` with next major release
/// identifies the data type that we will encode into `byteBuffer` in `encode`
static var psqlType: PostgresDataType { get }
/// identifies the postgres format that is used to encode the value into `byteBuffer` in `encode`
static var psqlFormat: PostgresFormat { get }
/// Encode the entity into the `byteBuffer` in Postgres binary format, without setting
/// the byte count. This method is called from the ``PostgresBindings``.
func encode<JSONEncoder: PostgresJSONEncoder>(into byteBuffer: inout ByteBuffer, context: PostgresEncodingContext<JSONEncoder>) throws
}requires that all instances of a type are encoded into the same PostgresDataType because of the static requirement. This is bad, specifically because supporting custom types (like Postgres enums) requires a dynamic OID.
For this reason @gwynne proposes adding a PostgresDynamicTypeEncodable and PostgresDynamicTypeThrowingEncodable, that use dynamic psqlType and psqlFormat. PostgresEncodable should then inherit from the PostgresDynamicTypeThrowingEncodable and PostgresNonThrowingEncodable from PostgresDynamicTypeEncodable. Love how we ended up at the place with NonThrowing and just Throwing.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request