internal static async Task <DocumentLookupResult> LookupDocumentAsync(ICouchbaseCollection collection, string docId, TimeSpan?keyValueTimeout, bool fullDocument = true)
        {
            var specs = new List <LookupInSpec>()
            {
                LookupInSpec.Get(TransactionFields.TransactionInterfacePrefixOnly, isXattr: true),
                LookupInSpec.Get("$document", isXattr: true),
                LookupInSpec.Get(TransactionFields.StagedData, isXattr: true)
            };

            var opts = new LookupInOptions().Defaults(keyValueTimeout).AccessDeleted(true);

            int?txnIndex        = 0;
            int docMetaIndex    = 1;
            int?stagedDataIndex = 2;

            int?fullDocIndex = null;

            if (fullDocument)
            {
                specs.Add(LookupInSpec.GetFull());
                fullDocIndex = specs.Count - 1;
            }

            ILookupInResult lookupInResult;

            try
            {
                lookupInResult = await collection.LookupInAsync(docId, specs, opts).CAF();
            }
            catch (PathInvalidException)
            {
                throw;
            }

            var docMeta = lookupInResult.ContentAs <DocumentMetadata>(docMetaIndex);

            IContentAsWrapper?unstagedContent = fullDocIndex.HasValue
                ? new LookupInContentAsWrapper(lookupInResult, fullDocIndex.Value)
                : null;

            var stagedContent = stagedDataIndex.HasValue && lookupInResult.Exists(stagedDataIndex.Value)
                ? new LookupInContentAsWrapper(lookupInResult, stagedDataIndex.Value)
                : null;

            var result = new DocumentLookupResult(docId,
                                                  unstagedContent,
                                                  stagedContent,
                                                  lookupInResult,
                                                  docMeta,
                                                  collection);

            if (txnIndex.HasValue && lookupInResult.Exists(txnIndex.Value))
            {
                result.TransactionXattrs = lookupInResult.ContentAs <TransactionXattrs>(txnIndex.Value);
            }

            return(result);
        }
Example #2
0
        public async Task Can_do_lookup_in_with_array()
        {
            var collection = await _fixture.GetDefaultCollection();

            await collection.Upsert(DocumentKey, new { foo = "bar", bar = "foo" });

            var result = await collection.LookupIn(DocumentKey, new []
            {
                LookupInSpec.Get("foo"),
                LookupInSpec.Get("bar")
            });

            Assert.Equal("bar", result.ContentAs <string>(0));
            Assert.Equal("foo", result.ContentAs <string>(1));
        }
Example #3
0
        public async Task <(Dictionary <string, AtrEntry> attempts, ParsedHLC parsedHlc)> LookupAttempts(string atrId)
        {
            var opts  = new LookupInOptions().Timeout(_keyValueTimeout);
            var specs = new LookupInSpec[]
            {
                LookupInSpec.Get(TransactionFields.AtrFieldAttempts, isXattr: true),
                LookupInSpec.Get(ClientRecordsIndex.VBUCKET_HLC, isXattr: true)
            };

            var lookupInResult = await Collection.LookupInAsync(atrId, specs, opts).CAF();

            var attempts  = lookupInResult.ContentAs <Dictionary <string, AtrEntry> >(0);
            var parsedHlc = lookupInResult.ContentAs <ParsedHLC>(1);

            return(attempts, parsedHlc);
        }
Example #4
0
        public async Task <(ClientRecordsIndex?clientRecord, ParsedHLC parsedHlc, ulong?cas)> GetClientRecord()
        {
            var opts  = new LookupInOptions().Timeout(_keyValueTimeout);
            var specs = new LookupInSpec[]
            {
                LookupInSpec.Get(ClientRecordsIndex.FIELD_RECORDS, isXattr: true),
                LookupInSpec.Get(ClientRecordsIndex.VBUCKET_HLC, isXattr: true)
            };

            var lookupInResult = await Collection.LookupInAsync(ClientRecordsIndex.CLIENT_RECORD_DOC_ID, specs, opts).CAF();

            var parsedRecord = lookupInResult.ContentAs <ClientRecordsIndex>(0);
            var parsedHlc    = lookupInResult.ContentAs <ParsedHLC>(1);

            return(parsedRecord, parsedHlc, lookupInResult.Cas);
        }