Ejemplo n.º 1
0
        /// <summary>
        /// Collection into which to insert
        /// </summary>
        public AqlQuery In(string collectionName)
        {
            ArangoUtils.ValidateCollectionName(collectionName);
            CollectionName = collectionName;

            doneCallback.Invoke(this);

            return(query);
        }
Ejemplo n.º 2
0
        public AqlRemoveOperation(
            AqlExpression keyExpression,
            string collectionName,
            JsonObject options = null
            )
        {
            ArangoUtils.ValidateCollectionName(collectionName);

            KeyExpression  = keyExpression;
            CollectionName = collectionName;
            Options        = options ?? new JsonObject();
        }
        public AqlInsertOperation(
            AqlExpression expression,
            string collectionName,
            JsonObject options = null
            )
        {
            ArangoUtils.ValidateCollectionName(collectionName);

            Expression     = expression;
            CollectionName = collectionName;
            Options        = options ?? new JsonObject();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates new collection of given type or throws an arango exception
        /// </summary>
        /// <exception cref="ArangoException"></exception>
        public Collection CreateCollection(
            string collectionName,
            CollectionType type
            )
        {
            if (Collections.ContainsKey(collectionName))
            {
                throw new ArangoException(409, 1207, "duplicate name");
            }

            ArangoUtils.ValidateCollectionName(collectionName);

            Collections[collectionName] = new Collection(collectionName, type);

            return(Collections[collectionName]);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Inserts a document into the collection with options and
        /// returns the exact value that will be stored after the insert
        /// </summary>
        public JsonObject InsertDocument(JsonObject document, JsonObject options)
        {
            if (document == null)
            {
                document = new JsonObject();
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (CollectionType == CollectionType.Edge)
            {
                ValidateEdgeAttributes(document);
            }

            string key = document["_key"].AsString ?? GenerateNewKey();

            ArangoUtils.ValidateDocumentKey(key);

            if (documents.ContainsKey(key) && !options["overwrite"])
            {
                // do not insert, but do not throw either
                if (options["ignoreErrors"])
                {
                    return(null); // ignore write
                }
                throw new ArangoException(
                          409, 1210, "unique constraint violated"
                          );
            }

            JsonObject insertedDocument = PrepareDocumentForWrite(
                GenerateNewRevision(),
                document
                );

            documents[key] = insertedDocument;

            return(PrepareDocumentForReturn(key, insertedDocument));
        }