-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC: Expand Patch Operations #465
base: main
Are you sure you want to change the base?
POC: Expand Patch Operations #465
Conversation
Apply latest changes
Updated DefaultRepository.Update.cs to return etag as value. |
@@ -1,55 +1,396 @@ | |||
// Copyright (c) David Pine. All rights reserved. | |||
// Copyright (c) IEvangelist. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Copyright (c) IEvangelist. All rights reserved. | |
// Copyright (c) David Pine. All rights reserved. |
|
||
internal class PatchOperationBuilder<TItem> : IPatchOperationBuilder<TItem> where TItem : IItem | ||
[assembly: InternalsVisibleTo("Microsoft.Azure.CosmosRepositoryTests")] | ||
namespace Microsoft.Azure.CosmosRepository.Builders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File-scoped namespaces please.
|
||
public IReadOnlyList<PatchOperation> PatchOperations => _patchOperations; | ||
internal class PatchOperationBuilder<TItem> : IPatchOperationBuilder<TItem> where TItem : IItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be sealed
?
_patchOperations.Add(PatchOperation.Replace($"/{propertyToReplace}", value)); | ||
public PatchOperationBuilder() => | ||
_namingStrategy = new CamelCaseNamingStrategy(); | ||
public PatchOperationBuilder(CosmosPropertyNamingPolicy? cosmosPropertyNamingPolicy) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, prefer primary constructor.
public PatchOperationBuilder(CosmosPropertyNamingPolicy? cosmosPropertyNamingPolicy) => | |
public PatchOperationBuilder(CosmosPropertyNamingPolicy? cosmosPropertyNamingPolicy) => |
return this; | ||
} | ||
|
||
private string NormalizePathPrefix(string path) => "/" + path.TrimStart('/').TrimEnd('/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer string interpolation.
Add Operation doesn't work properly with lambda. var tenantId = Guid.Parse("fd048274-190c-4e50-90ff-f2bb84974523");
var companyId = Guid.Parse("c4707548-5033-4c00-9735-9268c326c04a");
// Create a company with the new properties
var company = new Company
{
TenantId = tenantId,
CompanyId = companyId,
Id = companyId.ToString(),
CompanyName = "Tech Innovations Inc.",
Industry = "Software Development",
Location = "Silicon Valley, CA",
YearFounded = 2005,
IsPublic = true,
Revenue = 1200000000m, // 1.2 Billion USD
Website = "https://www.techinnovations.com",
Manager = new CompanyEmployee
{
EmployeeId = 3,
FullName = "Johh Walker",
Position = "CEO",
Salary = 170000m,
EmployeeAddress = new Address
{
Street = "456 Oak St",
City = "aaaa",
State = "IL",
ZipCode = "62705"
}
},
Departments = new List<Department>
{
new Department
{
DepartmentId = 101,
DepartmentName = "Engineering",
ManagerName = "Alice Johnson",
Employees = new List<CompanyEmployee>
{
new CompanyEmployee
{
EmployeeId = 1,
FullName = "John Doe",
Position = "Software Engineer",
Salary = 80000m,
EmployeeAddress = new Address
{
Street = "123 Main St",
City = "Springfield",
State = "IL",
ZipCode = "62704"
}
}
}
},
new Department
{
DepartmentId = 102,
DepartmentName = "Marketing",
ManagerName = "Bob Williams",
Employees = new List<CompanyEmployee>
{
new CompanyEmployee
{
EmployeeId = 2,
FullName = "Jane Smith",
Position = "Marketing Specialist",
Salary = 70000m,
EmployeeAddress = new Address
{
Street = "456 Oak St",
City = "Springfield",
State = "IL",
ZipCode = "62705"
}
}
}
}
}
};
Cosmos exception This is due the fact that Needs more work. Edit: Format Markdown |
Related to #442, #307, #297
Implementation to support replace, set, add, remove, increment patch operations, excluding move.
Both implementations follow expression + path, inspired by #307 .
Expression approach can't work with ArrayIndexExpression (
x => x.Address.Tags[0]
), can make it work if it brings value, nevertheless same goal can be achieved over string path approach (/address/tags/0
)Questions
Need feedback regarding approach and any major optimizations we can perform. @IEvangelist @mumby0168
Tasks