Hi everyone. As an educational exercise I decided ...
# feed
a
Hi everyone. As an educational exercise I decided to implement (part of) the Postgres Wire Protocol in pure Kotlin. So I have a pure Kotlin Postgres Client now that uses coroutines and have tested it on JVM, JS Node, JS WASM and Apple ARM64. Take a look! https://github.com/helico-tech/postgreskt Most of the coroutine and network programming was pretty new to me, so I probably made quite some errors there, so I don't mind any feedback and pointers. It is not my plan at all to use this in production AND YOU SHOULDN'T EITHER and this was purely an exercise. To be honest, it wasn't that hard. I spent most time figuring out bugs in byte encoding and decoding. I found out the Jetbrains AI / Junie is actually pretty good in pointing those out.
K 7
s
Oh great, going to use this in production... 😆
😄 3
a
I omitted SASL auth because I thought it was too difficult (and out of scope). I just asked Junie and she(?) implemented it, so I've updated that 😄
s
Indeed. I refer to basically all AIs as "he" (and sometimes "it"), but Junie sounds like a female name to me, so it's the only AI I call "she".
My female trainee, however, refers all AIs as "she".
In German you would say "die künstliche Intelligenz" where "die" is "she". So I can see where she's coming from. I consider ChatGPT somehow as my coding Bro, so it's obviously a dude. 🫣
See how a single
(?)
is enough for me going far off-topic, lol.
😄 2
a
Dutch is, 'de kunstmatige intelligentie', so same 😉
1
c
Nice, I'm soon going to do the same for MongoDB 👀 ktmongo.opensavvy.dev
👍 2
👍🏾 1
I'm planning on going with Ktor Sockets and KotlinX.IO, are there any footguns/lessons you would have wanted to know before you started?
a
I also use Ktor Sockets and Kotlinx IO. I must say it worked pretty good and easy! Just don't do anything too fancy with the Buffers, because you empty them before you know it.
c
At this point I have the code to read/write most data from buffers, the next steps are to finish plugging KotlinX.Serialization on top, and then it's TCP fun
a
Nice. I can't say anything about the Mongo TCP implementation. But Postgres was basically some custom serialization and pushing messages over the wire. The only caveat was that it isn't request - response, but a full async protocol which is also pretty stateful. So that's why I've implemented it as a very tiny state machine.
Postgres can send you messages to give you updates about server parameters etc at any moment.
c
nice, interesting
a
What was interesting from this approach was that LISTEN/NOTIFY comes naturally from this implementation and you have a multi-producer fan-out message bus for free
c
Thanks to coroutines channels, right?
a
No I mean on Postgres level on how notifications work. With my client you can have multiple client listen and notify to a postgres channel.
👍 1