public async Task <List <string> > ListCollectionsAsync(ArangoHandle database,
                                                                CancellationToken cancellationToken = default)
        {
            var res = await SendAsync <QueryResponse <JObject> >(HttpMethod.Get,
                                                                 $"{Server}/_db/{DbName(database)}/_api/collection?excludeSystem=true",
                                                                 cancellationToken : cancellationToken);

            return(res.Result.Select(x => x.Value <string>("name")).ToList());
        }
示例#2
0
        /// <summary>
        ///     AQL filter expression with x as iterator
        /// </summary>
        public async Task <List <T> > FindAsync <T>(ArangoHandle database, string collection, FormattableString filter,
                                                    string projection = null, int limit = 1000, CancellationToken cancellationToken = default) where T : new()
        {
            var filterExp = Parameterize(filter, out var parameter);

            return(await QueryAsync <T>(database,
                                        $"FOR x IN {collection} FILTER {filterExp} LIMIT {limit} RETURN {projection ?? "x"}",
                                        parameter, cancellationToken : cancellationToken));
        }
 public async Task CreateAnalyzerAsync(ArangoHandle database,
                                       ArangoAnalyzer analyzer,
                                       CancellationToken cancellationToken = default)
 {
     await SendAsync <QueryResponse <JObject> >(HttpMethod.Post,
                                                $"{Server}/_db/{DbName(database)}/_api/analyzer",
                                                JsonConvert.SerializeObject(analyzer, JsonSerializerSettings),
                                                cancellationToken : cancellationToken);
 }
        public async Task DropViewsAsync(ArangoHandle database, CancellationToken cancellationToken = default)
        {
            var views = await ListViewsAsync(database, cancellationToken);

            foreach (var view in views)
            {
                await DropViewAsync(database, view, cancellationToken);
            }
        }
        public async Task <List <string> > ListViewsAsync(ArangoHandle database,
                                                          CancellationToken cancellationToken = default)
        {
            var res = await SendAsync <JObject>(HttpMethod.Get,
                                                $"{Server}/_db/{DbName(database)}/_api/view",
                                                cancellationToken : cancellationToken);

            return(res.GetValue("result")
                   .Select(x => x.Value <string>("name")).ToList());
        }
        public async Task <bool> CreateDatabaseAsync(ArangoHandle name, CancellationToken cancellationToken = default)
        {
            var res = await SendAsync <JObject>(HttpMethod.Post,
                                                $"{Server}/_db/_system/_api/database",
                                                JsonConvert.SerializeObject(new
            {
                name = Realm + name
            }), throwOnError : false, cancellationToken : cancellationToken);

            return(res != null);
        }
 public async Task CreateCollectionAsync(ArangoHandle database, string collection, ArangoCollectionType type,
                                         CancellationToken cancellationToken = default)
 {
     await SendAsync <JObject>(HttpMethod.Post,
                               $"{Server}/_db/{DbName(database)}/_api/collection",
                               JsonConvert.SerializeObject(new ArangoCollection
     {
         Name = collection,
         Type = type
     }, JsonSerializerSettings), cancellationToken : cancellationToken);
 }
示例#8
0
        public async Task AbortTransactionAsync(ArangoHandle database, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrWhiteSpace(database.Transaction))
            {
                throw new ArangoException("no transaction handle");
            }

            await SendAsync <JObject>(HttpMethod.Delete,
                                      $"{Server}/_db/{DbName(database)}/_api/transaction/{database.Transaction}",
                                      cancellationToken : cancellationToken);
        }
示例#9
0
        public async Task <ArangoHandle> BeginTransactionAsync(ArangoHandle database, ArangoTransaction request,
                                                               CancellationToken cancellationToken = default)
        {
            var res = await SendAsync <JObject>(HttpMethod.Post,
                                                $"{Server}/_db/{DbName(database)}/_api/transaction/begin",
                                                JsonConvert.SerializeObject(request, JsonSerializerSettings), cancellationToken : cancellationToken);

            var transaction = res.GetValue("result").Value <string>("id");

            return(new ArangoHandle(database, transaction));
        }
示例#10
0
        public async Task <ArangoUpdateResult <JObject> > ReplaceDocumentAsync <T>(ArangoHandle database, string collection,
                                                                                   T doc,
                                                                                   bool waitForSync = false,
                                                                                   bool?returnOld   = null,
                                                                                   bool?returnNew   = null,
                                                                                   CancellationToken cancellationToken = default) where T : class
        {
            var res = await ReplaceDocumentsAsync <T, JObject>(database, collection, new List <T> {
                doc
            },
                                                               waitForSync, returnOld, returnNew, cancellationToken);

            return(res.SingleOrDefault());
        }
        /// <summary>
        ///     Drops all user created indices over all collections in database
        /// </summary>
        public async Task DropIndicesAsync(ArangoHandle database, CancellationToken cancellationToken = default)
        {
            var collections = await ListCollectionsAsync(database, cancellationToken);

            foreach (var col in collections)
            {
                var indices = await ListIndicesAsync(database, col, cancellationToken);

                foreach (var idx in indices)
                {
                    await DropIndexAsync(database, idx, cancellationToken);
                }
            }
        }
示例#12
0
        /// <summary>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="database"></param>
        /// <param name="collection"></param>
        /// <param name="docs"></param>
        /// <param name="waitForSync"></param>
        /// <param name="silent"></param>
        /// <param name="overwrite">In bulk mode truncates collection!</param>
        /// <param name="bulk">Optimized insert</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task CreateDocumentsAsync <T>(ArangoHandle database, string collection, IEnumerable <T> docs,
                                                   bool waitForSync = false,
                                                   bool silent      = true,
                                                   bool overwrite   = false,
                                                   bool bulk        = false,
                                                   CancellationToken cancellationToken = default) where T : class
        {
            if (bulk)
            {
                var query = AddQueryString($"{Server}/_db/{DbName(database)}/_api/import",
                                           new Dictionary <string, string>
                {
                    { "type", "array" },
                    { "complete", "true" },
                    { "overwrite", overwrite.ToString().ToLowerInvariant() },
                    { "collection", collection }
                });

                var res = await SendAsync <JObject>(HttpMethod.Post, query,
                                                    JsonConvert.SerializeObject(docs, JsonSerializerSettings),
                                                    cancellationToken : cancellationToken);
            }
            else
            {
                var query = AddQueryString(
                    $"{Server}/_db/{DbName(database)}/_api/document/{UrlEncoder.Default.Encode(collection)}",
                    new Dictionary <string, string>
                {
                    { "waitForSync", waitForSync.ToString().ToLowerInvariant() },
                    { "silent", silent.ToString().ToLowerInvariant() },
                    { "overwrite", overwrite.ToString().ToLowerInvariant() }
                });

                var res = await SendAsync <JArray>(HttpMethod.Post, query,
                                                   JsonConvert.SerializeObject(docs, JsonSerializerSettings),
                                                   database.Transaction, cancellationToken : cancellationToken);

                if (res != null)
                {
                    foreach (var r in res)
                    {
                        if (r.Value <bool>("error"))
                        {
                            throw new ArgumentException(res.ToString());
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Ignores primary and edge indices
        /// </summary>
        public async Task <List <string> > ListIndicesAsync(ArangoHandle database, string collection,
                                                            CancellationToken cancellationToken = default)
        {
            var res = await SendAsync <JObject>(HttpMethod.Get,
                                                $"{Server}/_db/{DbName(database)}/_api/index?collection={UrlEncoder.Default.Encode(collection)}",
                                                cancellationToken : cancellationToken);

            return(res.GetValue("indexes")
                   .Where(x =>
            {
                var type = x.Value <string>("type");
                return type != "primary" && type != "edge";
            })
                   .Select(x => x.Value <string>("id")).ToList());
        }
示例#14
0
        public async Task <ArangoUpdateResult <TR> > UpdateDocumentAsync <T, TR>(ArangoHandle database, string collection,
                                                                                 T doc,
                                                                                 bool?waitForSync  = null,
                                                                                 bool?keepNull     = null,
                                                                                 bool?mergeObjects = null,
                                                                                 bool?returnOld    = null,
                                                                                 bool?returnNew    = null,
                                                                                 bool?silent       = null,
                                                                                 CancellationToken cancellationToken = default) where T : class
        {
            var res = await UpdateDocumentsAsync <T, TR>(database, collection,
                                                         new List <T> {
                doc
            }, waitForSync, keepNull, mergeObjects,
                                                         returnOld, returnNew, silent, cancellationToken);

            return(res.SingleOrDefault());
        }
示例#15
0
        public async Task <T> CreateDocumentAsync <T>(ArangoHandle database, string collection, T doc,
                                                      bool waitForSync = false,
                                                      bool silent      = true,
                                                      bool overwrite   = false,
                                                      CancellationToken cancellationToken = default) where T : class
        {
            var query = AddQueryString(
                $"{Server}/_db/{DbName(database)}/_api/document/{UrlEncoder.Default.Encode(collection)}",
                new Dictionary <string, string>
            {
                { "waitForSync", waitForSync.ToString().ToLowerInvariant() },
                { "silent", silent.ToString().ToLowerInvariant() },
                { "overwrite", overwrite.ToString().ToLowerInvariant() }
            });

            var res = await SendAsync <DocumentCreateResponse <T> >(HttpMethod.Post, query,
                                                                    JsonConvert.SerializeObject(doc, JsonSerializerSettings),
                                                                    database.Transaction, cancellationToken : cancellationToken);

            return(doc);
        }
示例#16
0
        public async Task <List <ArangoUpdateResult <TR> > > UpdateDocumentsAsync <T, TR>(ArangoHandle database,
                                                                                          string collection, IEnumerable <T> docs,
                                                                                          bool?waitForSync  = null,
                                                                                          bool?keepNull     = null,
                                                                                          bool?mergeObjects = null,
                                                                                          bool?returnOld    = null,
                                                                                          bool?returnNew    = null,
                                                                                          bool?silent       = null,
                                                                                          CancellationToken cancellationToken = default) where T : class
        {
            var parameter = new Dictionary <string, string>();

            if (waitForSync.HasValue)
            {
                parameter.Add("waitForSync", waitForSync.Value.ToString().ToLowerInvariant());
            }

            if (keepNull.HasValue)
            {
                parameter.Add("keepNull", keepNull.Value.ToString().ToLowerInvariant());
            }

            if (mergeObjects.HasValue)
            {
                parameter.Add("mergeObjects", mergeObjects.Value.ToString().ToLowerInvariant());
            }

            if (returnOld.HasValue)
            {
                parameter.Add("returnOld", returnOld.Value.ToString().ToLowerInvariant());
            }

            if (returnNew.HasValue)
            {
                parameter.Add("returnNew", returnNew.Value.ToString().ToLowerInvariant());
            }

            if (silent.HasValue)
            {
                parameter.Add("silent", silent.Value.ToString().ToLowerInvariant());
            }

            var query = AddQueryString(
                $"{Server}/_db/{DbName(database)}/_api/document/{UrlEncoder.Default.Encode(collection)}", parameter);

            return(await SendAsync <List <ArangoUpdateResult <TR> > >(HttpMethod.Patch, query,
                                                                      JsonConvert.SerializeObject(docs, JsonSerializerSettings),
                                                                      database.Transaction, cancellationToken : cancellationToken));
        }
示例#17
0
        public async Task <List <ArangoUpdateResult <TR> > > DeleteDocumentsAsync <T, TR>(ArangoHandle database,
                                                                                          string collection, IEnumerable <T> docs,
                                                                                          bool?waitForSync = null,
                                                                                          bool?returnOld   = null,
                                                                                          CancellationToken cancellationToken = default) where T : class
        {
            var parameter = new Dictionary <string, string>();

            if (waitForSync.HasValue)
            {
                parameter.Add("waitForSync", waitForSync.Value.ToString().ToLowerInvariant());
            }

            if (returnOld.HasValue)
            {
                parameter.Add("returnOld", returnOld.Value.ToString().ToLowerInvariant());
            }

            var query = AddQueryString(
                $"{Server}/_db/{DbName(database)}/_api/document/{collection}", parameter);

            return(await SendAsync <List <ArangoUpdateResult <TR> > >(HttpMethod.Delete, query,
                                                                      JsonConvert.SerializeObject(docs, JsonSerializerSettings),
                                                                      database.Transaction, cancellationToken : cancellationToken));
        }
示例#18
0
 public ArangoHandle(ArangoHandle other, string transaction)
 {
     Name        = other.Name;
     Transaction = transaction;
 }
示例#19
0
 /// <summary>
 ///     Constructs wrapping handle with batch
 /// </summary>
 public ArangoHandle(ArangoHandle other, bool batch)
 {
     Name        = other.Name;
     Transaction = other.Transaction;
     Batches     = new List <ArangoBatch>();
 }
示例#20
0
 public async Task <List <ArangoUpdateResult <JObject> > > ReplaceDocumentsAsync <T>(ArangoHandle database,
                                                                                     string collection, IEnumerable <T> docs,
                                                                                     bool?waitForSync = null,
                                                                                     bool?returnOld   = null,
                                                                                     bool?returnNew   = null,
                                                                                     CancellationToken cancellationToken = default) where T : class
 {
     return(await ReplaceDocumentsAsync <T, JObject>(database, collection, docs,
                                                     waitForSync, returnOld, returnNew, cancellationToken));
 }
 public async Task DropDatabaseAsync(ArangoHandle name, CancellationToken cancellationToken = default)
 {
     await SendAsync <JObject>(HttpMethod.Delete,
                               $"{Server}/_db/_system/_api/database/{DbName(name)}", null,
                               throwOnError : false, cancellationToken : cancellationToken);
 }
        public async Task <bool> ExistDatabaseAsync(ArangoHandle name, CancellationToken cancellationToken = default)
        {
            var dbs = await ListDatabasesAsync(cancellationToken);

            return(dbs.Contains(name));
        }
 public async Task DropIndexAsync(ArangoHandle database, string index,
                                  CancellationToken cancellationToken = default)
 {
     await SendAsync <JObject>(HttpMethod.Delete,
                               $"{Server}/_db/{DbName(database)}/_api/index/{index}", cancellationToken : cancellationToken);
 }