FDB doesn’t support tables, it just a key-value store (the tuple layer is shipped with the client, but there’s no obligation to use it).
Yes, I am aware of that. I used the tables illustration to depict my mental model of the data.
So if you want to store relational data in FDB you have to come up with a scheme how you want to translate this to keys and values – and there’s many ways of doing this.
The Tuple structure I mentioned in my original post is my understanding, after reading the documentation and Tuple implementation on GitHub, of how to translate the mental model of a relational table into key-value pairs. So I will elaborate on my original example below with the representation of a table entry into key-value pairs. Taking the example of a Student table:
Student{id:uuid, name:string, address:string}
An entry in FDB for this table could be as follows(for illustration purpose I am using descriptive names for the API rather than the actual names below):
S = directory("student")
S.add_key_value(tuple{uuid, "name"}, name_value)
S.add_key_value(tuple{uuid, "address"}, address_value)
As per my understanding, this will create two keys directory_id+uuid+"name"
and directory_id+uuid+"address"
with the values name_value
and address_value
respectively. And I think, now to create an index to find what courses the student is taking, additional key-value pairs could be added per course taken:
S.add_key_value(tuple{uuid, "course", course_uuid}, "")
This will create the key directory_id+uuid+"course"+course_uuid
with empty value. Then to find all the courses taken by a student with id uuid
, all the keys with prefix directory_id+uuid+"course"
should be fetched.
Similarly, the table Course could be translated into key-value pair with the index entries for students that have taken that particular course.
This is my understanding of how a mental model of a relational table can be translated to key-value pairs in FDB. Using this understanding, my question was whether there is a way to compress the size of the keys(and hence the overall storage space).