So I wrote a backend for this thing:
http://sophia.systems/
It looks really nice, but sadly it doesn't seem to offer cursors that can
iterate inside the current transaction, as can be seen from the example program
attached. The output is:
a: aval
b: bval
c: cval
d: outside
Where I would expect:
a: aval
b: bval
c: cval
d: inside
I haven't been able to find a way around this. I thought using the "order" ops
directly rather than the sp_cursor would do it, but it has the same bug :(
It also doesn't support BYO sort order, which means no improved_mboxlist_sort
support.
*sigh* - back to the drawing board.
Bron.
--
Bron Gondwana
[email protected]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sophia.h"
struct kv {
const char *k;
const char *v;
};
int main(char **argv, int argc)
{
void *env = sp_env();
sp_setstring(env, "sophia.path", "/tmp/testdb", 0);
sp_setstring(env, "db", "test", 0);
sp_open(env);
struct kv set[] = {
{ "a", "aval" },
{ "b", "bval" },
{ "c", "cval" },
{ NULL, NULL },
};
void *db = sp_getobject(env, "db.test");
int i;
void *o;
for (i = 0; set[i].k; i++) {
o = sp_document(db);
sp_setstring(o, "key", set[i].k, strlen(set[i].k));
sp_setstring(o, "value", set[i].v, strlen(set[i].v));
sp_set(db, o);
}
void *t = sp_begin(env);
o = sp_document(db);
sp_setstring(o, "key", "d", 1);
sp_setstring(o, "value", "outside", 7);
sp_set(db, o);
o = sp_document(db);
sp_setstring(o, "key", "d", 1);
sp_setstring(o, "value", "inside", 6);
sp_set(t, o);
o = sp_document(db);
sp_setstring(o, "order", ">=", 0);
while ((o = sp_get(t, o))) {
int keylen;
char *key = sp_getstring(o, "key", &keylen);
int valuelen;
char *value = sp_getstring(o, "value", &valuelen);
printf("%.*s: %.*s\n", keylen, key, valuelen, value);
}
sp_commit(t);
sp_destroy(env);
return 0;
}