/// <summary> /// Adds the given document to the collection unless the identifier or any other field that has a unique index /// already exists, in which case it will update the matching document. /// </summary> /// <param name="id">The unique identifier of the document to replace.</param> /// <param name="doc">The document to replace the matching document.</param> /// <returns>A <see cref="Result"/> object containing the results of the execution.</returns> /// <exception cref="MySqlException">The server version is lower than 8.0.3.</exception> /// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c> or white space.</exception> /// <exception cref="ArgumentNullException"><paramref name="doc"/> is <c>null</c>.</exception> /// <exception cref="FormatException">The <paramref name="id"/> is different from the one in <paramref name="doc"/>.</exception> /// <remarks>This is a direct execution method.</remarks> public Result AddOrReplaceOne(object id, object doc) { if (!this.Session.InternalSession.GetServerVersion().isAtLeast(8, 0, 3)) { throw new MySqlException(string.Format(ResourcesX.FunctionalityNotSupported, "8.0.3")); } if (id == null) { throw new ArgumentNullException(nameof(id)); } string stringId = id.ToString(); if (string.IsNullOrWhiteSpace(stringId)) { throw new ArgumentNullException(nameof(id), Resources.ParameterNullOrEmpty); } if (doc == null) { throw new ArgumentNullException(nameof(doc)); } DbDoc newDocument = doc is DbDoc ? doc as DbDoc : new DbDoc(doc); newDocument.Id = id; AddStatement stmt = Add(newDocument); stmt.upsert = true; return(stmt.Execute()); }
/// <summary> /// Creates an <see cref="AddStatement"/> containing the provided objects that can be used to add /// one or more items to a collection. /// </summary> /// <param name="items">The objects to add.</param> /// <returns>An <see cref="AddStatement"/> object containing the objects to add.</returns> /// <exception cref="ArgumentNullException"><paramref name="items"/> is <c>null</c>.</exception> /// <remarks>This method can take anonymous objects, domain objects, or just plain JSON strings. /// The statement can be further modified before execution.</remarks> public AddStatement Add(params object[] items) { if (items == null) { throw new ArgumentNullException(); } AddStatement stmt = new AddStatement(this); stmt.Add(items); return(stmt); }
public static void OnCodeElement(AddStatement statement, CodeElementsParser.AddStatementContext context) { var givingStatement = statement as AddGivingStatement; if (givingStatement == null) { return; //not our job } if (givingStatement.Operand == null) { DiagnosticUtils.AddError(givingStatement, "Required: <identifier> after TO", context?.addGiving()); } }
protected Result ExecuteAddStatement(AddStatement stmt) { return(stmt.Execute()); }