* ObjectControllerTests.cs: chore: 支持 FetchWhenSave
* AVObject.cs: * AVObjectController.cs:
parent
862df7c6fa
commit
2a735cd89a
|
@ -24,12 +24,12 @@ namespace LeanCloudTests {
|
|||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveWithQuery() {
|
||||
public async Task SaveWithOptions() {
|
||||
AVObject account = AVObject.CreateWithoutData("Account", "5d65fa5330863b008065e476");
|
||||
AVQuery<AVObject> query = new AVQuery<AVObject>("Account");
|
||||
query.WhereGreaterThan("balance", 80);
|
||||
account["balance"] = 50;
|
||||
await account.SaveAsync(query);
|
||||
await account.SaveAsync(true, query);
|
||||
TestContext.Out.WriteLine($"balance: {account["balance"]}");
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace LeanCloud.Storage.Internal {
|
|||
|
||||
public Task<IObjectState> SaveAsync(IObjectState state,
|
||||
IDictionary<string, IAVFieldOperation> operations,
|
||||
bool fetchWhenSave,
|
||||
AVQuery<AVObject> query,
|
||||
string sessionToken,
|
||||
CancellationToken cancellationToken) {
|
||||
|
@ -45,12 +46,16 @@ namespace LeanCloud.Storage.Internal {
|
|||
Method = state.ObjectId == null ? HttpMethod.Post : HttpMethod.Put,
|
||||
Content = objectJSON
|
||||
};
|
||||
Dictionary<string, object> args = new Dictionary<string, object>();
|
||||
if (fetchWhenSave) {
|
||||
args.Add("fetchWhenSave", fetchWhenSave);
|
||||
}
|
||||
// 查询条件
|
||||
if (query != null && query.where != null) {
|
||||
Dictionary<string, object> where = new Dictionary<string, object> {
|
||||
{ "where", PointerOrLocalIdEncoder.Instance.Encode(query.where) }
|
||||
};
|
||||
string encode = AVClient.BuildQueryString(where);
|
||||
args.Add("where", PointerOrLocalIdEncoder.Instance.Encode(query.where));
|
||||
}
|
||||
if (args.Count > 0) {
|
||||
string encode = AVClient.BuildQueryString(args);
|
||||
command.Path = $"{command.Path}?{encode}";
|
||||
}
|
||||
return AVPlugins.Instance.CommandRunner.RunCommandAsync<IDictionary<string, object>>(command, cancellationToken: cancellationToken).OnSuccess(t => {
|
||||
|
|
|
@ -557,7 +557,7 @@ string propertyName
|
|||
}
|
||||
}
|
||||
|
||||
public virtual Task SaveAsync(AVQuery<AVObject> query = null, CancellationToken cancellationToken = default) {
|
||||
public virtual Task SaveAsync(bool fetchWhenSave = false, AVQuery<AVObject> query = null, CancellationToken cancellationToken = default) {
|
||||
IDictionary<string, IAVFieldOperation> currentOperations = null;
|
||||
if (!IsDirty) {
|
||||
return Task.FromResult(0);
|
||||
|
@ -577,6 +577,7 @@ string propertyName
|
|||
return deepSaveTask.OnSuccess(_ => {
|
||||
return ObjectController.SaveAsync(state,
|
||||
currentOperations,
|
||||
FetchWhenSave || fetchWhenSave,
|
||||
query,
|
||||
sessionToken,
|
||||
cancellationToken);
|
||||
|
@ -1501,6 +1502,10 @@ string propertyName
|
|||
}
|
||||
}
|
||||
|
||||
public bool FetchWhenSave {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this AVObject has unsaved changes.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue