Created
November 27, 2018 16:40
-
-
Save daschl/ea955f066981b36e13eb2208d1049294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- 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