Custom ID serialisation and deserialisation to get around the bug with uint64 storage in Postgres.