extend RC { transient RemoteDB db; S getString(S field) { ret db.xS(this, field); } void set(S field, O value) { db.xset(this, field, value); } } static class RemoteDB { DialogIO db; // s = bot name or snippet ID *(S s) { if (isSnippetID(s)) s = dbBotName(s); db = findBot(s); } bool functional() { ret db != null; } L list() { ret adopt((L) rpc(db, "xlist")); } L list(S className) { ret adopt((L) rpc(db, "xlist", className)); } L xlist() { ret list(); } L xlist(S className) { ret list(className); } // adopt is an internal method L adopt(L l) { if (l != null) for (RC rc : l) adopt(rc); ret l; } RC adopt(RC rc) { if (rc != null) rc.db = this; ret rc; } S xclass(RC o) { ret (S) rpc(db, "xclass", o); } O xget(RC o, S field) { ret rpc(db, "xget", o, field); } S xS(RC o, S field) { ret (S) xget(o, field); } RC xgetref(RC o, S field) { ret adopt((RC) xget(o, field)); } void xset(RC o, S field, O value) { rpc(db, "xset", o, field, value); } RC uniq(S className) { RC ref = first(list(className)); if (ref == null) ref = xnew(className); ret ref; } RC xuniq(S className) { ret uniq(className); } RC xnew(S className, O... values) { ret adopt((RC) rpc(db, "xnew", className, values)); } void xdelete(RC o) { rpc(db, "xdelete", o); } void xdelete(L l) { rpc(db, "xdelete", l); } void close() { if (db != null) db.close(); } S fullgrab() { ret (S) rpc(db, "xfullgrab"); } S xfullgrab() { ret fullgrab(); } }