taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
ur5us has quit [Ping timeout: 272 seconds]
Sankalp has quit [Ping timeout: 240 seconds]
Sankalp has joined #crystal-lang
Sankalp has quit [Ping timeout: 240 seconds]
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
jmdaemon has quit [Ping timeout: 272 seconds]
Sankalp has joined #crystal-lang
taupiqueur has quit [Remote host closed the connection]
Stephie has quit [Quit: Fuck this shit, I'm out!]
Vexatos_ has quit [Quit: Client Quit]
Stephie has joined #crystal-lang
Vexatos has joined #crystal-lang
taupiqueur has joined #crystal-lang
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
yxhuvud has quit [Read error: Connection reset by peer]
taupiqueur has quit [Ping timeout: 244 seconds]
yxhuvud has joined #crystal-lang
jhass has quit [Ping timeout: 252 seconds]
jrayhawk has quit [Ping timeout: 252 seconds]
mikko has quit [Ping timeout: 252 seconds]
fifr` has joined #crystal-lang
fifr has quit [Ping timeout: 252 seconds]
oprypin has quit [Ping timeout: 252 seconds]
Flipez9 has joined #crystal-lang
jhass has joined #crystal-lang
oprypin has joined #crystal-lang
Flipez has quit [Ping timeout: 252 seconds]
Flipez9 is now known as Flipez
rymiel has quit [Ping timeout: 252 seconds]
jrayhawk has joined #crystal-lang
rymiel has joined #crystal-lang
mikko has joined #crystal-lang
mikko has joined #crystal-lang
mikko has quit [Changing host]
<FromGitter>
<Blacksmoke16> SamantazFox: I think we talked about this before, but would it be better to use `JSON::Serializable` such that the deserialization would straight up fail, which would be a clearer error indication?
<FromGitter>
<Blacksmoke16> then you could have another type that your code uses in a format you like, then will just have to handle mapping the `JSON::Serializable` type to your internal type
<SamantazFox>
Blacksmoke16: I see two problems with this solution
<SamantazFox>
1) We want to have as few errors as possible for the end user, so if some data is missing, we prefer to have a slightly broken experience rather than an error message
<SamantazFox>
2) the data structure is very complex (sometimes with many layers of arrays and objects) so we'd have to create tons of classes for the various possibilities. In addition to that, some fields depend on others, so parsing has to be done in a determined order...
<FromGitter>
<Blacksmoke16> thats fair, could still use an internal type, but just build it out via `JSON.parse`
<FromGitter>
<Blacksmoke16> if you're not already doing that
<SamantazFox>
`JSON.parse` with a block?
<FromGitter>
<Blacksmoke16> no i mean like instead of doing `parse response => pass `JSON::Any` around to use it in code` do like `parse response => use the `JSON::Any` type to build out some internal type that has all the data you need => pass internal type around to use it in code`
<FromGitter>
<Blacksmoke16> such that if/when the data structures changes, you just need to update how your internal obj is built out, and not everything downstream too
<SamantazFox>
yeah, that's mostly what we're doing
<FromGitter>
<Blacksmoke16> 👍 cool
<SamantazFox>
depends on where you're looking, though xD
<FromGitter>
<Blacksmoke16> yea that looks a lot more sane
<SamantazFox>
yeaaah xD
<SamantazFox>
slowly, we've been rewriting some large chunks
<FromGitter>
<Blacksmoke16> glad to hear
<FromGitter>
<Blacksmoke16> negotiation component working out well still for ya? :P
<SamantazFox>
Seems so
<SamantazFox>
nobody has been complaining x)
<FromGitter>
<Blacksmoke16> 💪 perfect
_ht has joined #crystal-lang
dostoyevsky2 has quit [Ping timeout: 272 seconds]
dostoyevsky2 has joined #crystal-lang
Flipez has quit [Changing host]
Flipez has joined #crystal-lang
ur5us has joined #crystal-lang
_ht has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
<FromGitter>
<ismasan> Hi. Hoping someone can point me in the right direction here: I have a parent Event class with many sub-classes. I want to store records for those classes in a Postgres table. Then when querying I want to deserialize each row into the appropriate sub-class. I'm guessing this is a common use case. Thanks in advance everyone!
taupiqueur has quit [Remote host closed the connection]
jmdaemon has joined #crystal-lang
<FromGitter>
<Blacksmoke16> Using the raw db driver, or an orm?
<FromGitter>
<ismasan> That's what I'm trying ATM, but I'm open to alternatives
<FromGitter>
<ismasan> I get how to deserialize rows into a single class (MyClass.from_rs(result_set))
<FromGitter>
<ismasan> but not sure how to deserialize into different types.
<FromGitter>
<Blacksmoke16> okay, so what i think you could do is override `.from_rs` on the abstract type, have the discriminator column always first in your queries, do like `disriminator = rs.read String`, then use that string over a case, then doing `SubType.from_rs rs` on the right type
<FromGitter>
<ismasan> To be clear in my PG table I have a `type` varchar column. My idea was to use that somehow to resolve which class to deserialize the row into.
<FromGitter>
<ismasan> right right that's what I was starting to try now, thanks
<FromGitter>
<ismasan> I'm declaring these types via a simple macro so perhaps I could generate the case statement there.
<FromGitter>
<Blacksmoke16> probably yea
<FromGitter>
<Blacksmoke16> have options
taupiqueur has joined #crystal-lang
taupiqueur has quit [Remote host closed the connection]