Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// --- Collection API ---
// full doc fetch
Optional<Document> doc = collection.get("id");
// full doc fetch, turns into subdoc actually
Optional<Document> doc = collection.get("id", getOptions().withExpiration(true));
// full doc insert (since we now return a doc, let's take a document!)
collection.insert(
Document.create("id", new JsonObject()),
insertOptions().persistTo(PersistTo.NONE)
);
// subdoc fetch
Document document = collection.lookupIn("id", new LookupSpec().get("foo.bar"), LookupOptions...);
// subdoc mutation
MutationResult result = collection.mutateIn("id", new MutationSpec().insert("foo.bar", new JsonObject()), MutationOptions...);
// ---- Document API ----
class Document {
public static <T> Document create(final String id, final T content) { ... }
public static <T> Document create(final String id, final T content, final Encoder<T> encoder) { ... }
public String id() { ... }
public Optional<Long> cas() { ... }
public Optional<Duration> expiration() { ... }
public JsonObject contentAsObject() { ... }
public JsonArray contentAsArray() { ... }
public <T> T contentAs(final Class<T> target) { ... }
public <T> T contentAs(final Class<T> target, final Decoder<T> decoder) { ... }
/**
* Enriches the current {@link Document} with a cas value.
*/
public Document withCas(final long cas) { ... }
}
// NOTE: how decoder is on the contentAs.. and since we store byte[] in raw form on doc creation we also need to do the encoding!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.