Conversation
|
|
Woo, awesome! |
* binaries * macaddr * name * tsvector * float extended
|
Added some more: I think I'm done now.
|
|
|
||
| decode(<<Date:?int32>>, _TypeInfo) -> | ||
| calendar:gregorian_days_to_date(Date + ?POSTGRESQL_GD_EPOCH). | ||
| decode_date(Date + ?POSTGRESQL_GD_EPOCH). |
There was a problem hiding this comment.
would be nice to verify that over the real postgresql server. But that's how it's done in epgsql.
There was a problem hiding this comment.
What do you mean "verify over the real postgresql server"?
There was a problem hiding this comment.
I mean, we are converting datetime to some integer and send it to PostgreSQL; then we read it back as integer and convert back to datetime using the same algorithm. So, what we send and what we will receive will be the same, but what should be verified is that this integer is interpreted as the same YYYY-MM-DD_HH:mm:ss as in Erlang.
Say, we have {{2019, 11, 9}, {19, 59, 0}} in erlang. We encode it to some integer, send it to postgres, but what if postgres interprets this integer as some other date? Are we sure ituses gregorian_days_to_date?
| %% TODO: fix truncation problem | ||
| %% prop_float4_codec() -> | ||
| %% ?FORALL(Val, proper_types:float(-999.99, 990.99), | ||
| %% proper_lib:codec(pg_float4, [], Val, fun canonical_float4/1)). |
There was a problem hiding this comment.
Guess can be fixed by smth like:
float32_gen() ->
?LET(F, proper_types:float(),
begin
<<F1:32/float>> = <<F:32/float>>,
F1
end).
so, truncation is done inside the generator, not inside the codec? Or is there any better solution?
|
|
||
| prop_int2_codec() -> | ||
| ?FORALL(Val, proper_lib:int16(), | ||
| proper_lib:codec(pg_int2, [], Val)). |
There was a problem hiding this comment.
I'm thinking now maybe we should add a guards to integer encoders that ensure that the value is within the allowed range, instead of silently truncating when overflown?
| proper_types:binary(). | ||
|
|
||
|
|
||
| json_struct() -> |
There was a problem hiding this comment.
I've tried to implement recursive generator for JSON, but failed to do so =) But it isn't needed really, because we are just doing term_to_binary anyway.
| prop_integer_codec() -> | ||
| ?FORALL(Val, proper_types:integer( | ||
| -170141183460469231731687303715884105728, | ||
| 170141183460469231731687303715884105728), |
There was a problem hiding this comment.
Should UUID be represented as signed integer?
There was a problem hiding this comment.
Yea, though pg_types supports integer, string and binary.
There was a problem hiding this comment.
I mean signed vs unsigned integer
|
Regarding numeric, I thought @starbelly already did code for handling numerics as tuples instead of floats... but I see it isn't in I'm still not sure what to do about persistent_term being used by types like array. I'm going to toy with recursive resolving today so that types don't have to be looked up in |
|
@tsloughter hmmm I did, but then i think we decided not to include it. I can send up a PR which adds a clause for it though. The original clause was |
|
@seriyps so I have a fix for the use of persistent_term in array and record. It looks like the only catch is that there is some case that there aren't oids available in the record type and it decodes without them because they can be found in the data being decoded https://github.com/tsloughter/pg_types/blob/master/src/pg_record.erl#L67-L69 I don't know when that is an issue that you wouldn't have the oids in Maybe it isn't something that actually has to be supported? |
|
Crap, the record decode without knowing the oids before hand is used for tuples. I was just adding a test for |
|
Only took 5 years, hehe, but I merged part of this through a separate PR #9 |
|
Cool, thanks! |
You didn't lose it, it's here https://github.com/tsloughter/pg_types/blob/master/src/pg_numeric.erl But you can't use tuples 😄 You'd have to add an abstraction layer, and maybe that's what you thought I did, instead at some point pgo was trying to use tuples in this way, but I did the work to fix up numerics originally, which was mostly carried over to this repo, here is the original PR to pgo
I'm not sure what the talk about persistent_term here is, but one does have to be very careful with it and also keep in mind that we don't know what people are doing with persistent_term in other libs that an app nor the app itself. |
Here it is used to store type information for mapping oids to types. I wanted to keep this library without having any dependency on the other library using it to pass anything but the binary postgres term and the type info for that term. This works everywhere but I don't remember the details but I think we could fix this by changing the api to accept a map of types. It just means |
Ahh, so, this would be stored in persistent_term and really never change except for hot code upgrades and restarts, is that correct? |
|
@starbelly right. |
Also, few bugs were fixed:
Mostly some basic types covered.