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