Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read/write offset #133

Open
laurentcau opened this issue Jan 26, 2022 · 2 comments
Open

read/write offset #133

laurentcau opened this issue Jan 26, 2022 · 2 comments

Comments

@laurentcau
Copy link

Hi,

That would be very very very helpful for us to have read and write (unqlite_kv_store/unqlite_kv_fetch) with dataoffset to partial update data or partial read.
Do you think it's doable ?

@symisc
Copy link
Owner

symisc commented Jan 27, 2022

Hi Laurent,

You can easily achieve this by relying on unqlite_kv_fetch_callback() for extracting offseted data inside your callback function, and using unqlite_kv_append() instead of unqlite_kv_store() to append/update your data.

@laurentcau
Copy link
Author

laurentcau commented Jan 27, 2022

No, I don't think this API allow what I need.
Here is small example:

struct SHeader
{
	int value0;
	int value1;
};

struct SData
{
	SHeader header;
	const char buffer[1024*1024*1024];
};

SData data;
unqlite_kv_store(pDb,"key0",4, &data.header, sizeof(data.header));
unqlite_kv_happend(pDb,"key0",4, data.buffer, sizeof(data.buffer));

Later I just need to increment value1 of the header. (For example you want to save an access counter.)
with offset API I would do:

int value1=0;
unqlite_kv_fetch(pDb,"key0",4, &value1, sizeof(value1), offsetof(SHeader, value1) );
value1++;
unqlite_kv_store(pDb,"key0",4, &value1, sizeof(value1), offsetof(SHeader, value1) );

How would you do with the current API ?
You can use unqlite_kv_fetch_callback() to get the beginning of the Value. But if I place the header at the end of the value, I need to loop many times with the call back to retrieve the data I need.
But there is no way to write a small part, so, in fact you need to read all the data (GB in this case), make the change and write them back.

You can find other example if you think about implementing a file system.
I think a "seek" function is a must have for such application.
I don't see how you could implement that with the current API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants