I wrote a library in TypeScript which stores patch sets (changes of values 
based on keys). So a document is a final states (key value array) and a 
changelog. I use JSON(P) because because PG and TS can easily handle it.

Now Nim can handle JSON but you loose all typing guarantees. Using Nim 
datatypes means you need to teach PG how to work with it. That can be done 
cause you can load shared libraries.

But what would be the most efficient way to store the data ?

So when doing a select sum( my_nim_pg_code_get_value(data, "value") ) ?

I have like two solutions in my mind:

  1. use binary data where pointer reference itself. Something like first 4 
bytes point to start structure. Then continue treating binary data as if it was 
memory (but use memory pointers relative to start of the binary dump).
  2. just use a binary dump and unserialize (which might take more time and 
require more allocations/freeing)



I noticed that my simple key value store is somewhat limited cause I need sets 
and change operations which are more complex such as 'append to list' for chat 
logs whatever.

so my simple model would eat up much more memory than needed fast.

The main question is: If NIM cannot type JSON (like TS). What's the equivalent 
of document storage ? Create objects and unserialize/serialize from JSON ?

Reply via email to