Currently there are convenience initializers for creating PostgresData
s for commonly used types. That's not the case for Postgres' point
type. The initializer for a PostgresData
looks like this:
public init(
type: PostgresDataType,
typeModifier: Int32? = nil,
formatCode: PostgresFormat = .binary,
value: ByteBuffer? = nil
)
I'm trying to figure out what value should be provided for each parameter in order to get a PostgresData
that represents a point
.
Details
For type
, there already is a PostgresDataType
for a point
, namely PostgresDataType.point
, so that's what I'm using.
For typeModifier
, I'm confused as to what it's asking for. It is optional so may not be necessary in this case, but the documentation of the property hints otherwise. It says:
/// The type modifier (see pg_ attribute.atttypmod). The meaning of the modifier is type-specific.
public var typeModifier: Int32?
The documentation for the property states this:
atttypmod
records type-specific data supplied at table creation time (for example, the maximum length of avarchar
column). It is passed to type-specific input functions and length coercion functions. The value will generally be -1 for types that do not needatttypmod
.
It seems like .none
can be passed for the value because there doesn't really seem like there would be any type-specific data that would apply to a point
column like it would for a varchar
, but I was expecting a list of types with possible values for this property in the PostgreSQL documentation. This is because the PostgresNIO documentation indicates that the meaning of PostgresData.typeModifier
is "type-specific", which to me, indicates that there would be a list of the different values for different types and what those values mean for each type. I haven't been able to find that list.
For formatCode
it's either .text
or .binary
. I attempted to look over the wire protocol documentation for details regarding the format of different types, but found no such list. I noticed PostgresData
s for String
s are passed .binary
for this parameter. That said point
types — when using the PostgreSQL client — are included in the VALUES
section of a statement as a tuple of two 64-bit floating point numbers, but this tuple is provided as a string (in quotes). But so are strings. So I'm not quite sure what should be passed for this value either.
Then there's value
which for a String
are just the backing UTF8 bytes. It seems like the most efficient way to do this would be to encode two 64-bit floating point values back to back, but trying to construct the correct format by trial and error doesn't seem particularly wise.