-
Notifications
You must be signed in to change notification settings - Fork 25
Add support to Encodable types for addDocuments function #53
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
Conversation
|
Is this PR ready for review? Because it's still a draft 🙂 |
c1ce030 to
650ab3e
Compare
|
bors try |
tryMerge conflict. |
|
There is merge conflicts, bors can't do the rebase for you, sorry... Could you rebase your branch, please? 🙂 @ppamorim |
650ab3e to
6ad3cf4
Compare
a3a2671 to
e1181db
Compare
|
bors try |
tryBuild failed: |
|
bors try |
tryBuild succeeded: |
bidoubiwa
left a comment
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 you make a test where we add documents without jsonEncode them? Something like this
func testAddDataAndGetDocuments() {
let expectation = XCTestExpectation(description: "Add or replace Movies document")
self.client.addDocuments(
UID: self.uid,
documents: movies, //We use movies directly
primaryKey: nil
) { result in
...
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.
@ppamorim Two questions:
-
If I understand, we add another
addDocumentsmethod additionally to the previously existing one. Does this mean you can use theaddDocumentsmethod with or without the encodable support? Maybe I don't understand well, but what the point for the user to use a function that does not handle encodable types? I mean, should we let both of the methodaddDocuments? -
Should we add this functionality to the
updateDocumentsmethod? Not mandatory in this PR, but at least an issue should be created. The #37 is maybe not really accurate. In general, are there any other functions concerned by this user-experience improvement? @bidoubiwa
Answers in order: [0]:
Ex: This code gets outdated: let movie: Movie = Movie(id: 10, title: "test", comment: "test movie")
let documents: Data = try! JSONEncoder().encode([movie])
self.client.addDocuments(
UID: uid,
documents: documents,
primaryKey: nil) { ... }Now the user is capable of simply sending the values directly: let movie: Movie = Movie(id: 10, title: "test", comment: "test movie")
self.client.addDocuments(
UID: uid,
documents: [movie],
primaryKey: nil) { ... }The library will do all the [1]:
|
|
@curquiza Missed to inform that if the user contains requires a custom date format, it can be passed as an argument by using the parameter |
|
Yes I understand why what you are implementing in this PR is useful, I don't understand why we keep the outdated function in our code base, I mean the function used in this case: let movie: Movie = Movie(id: 10, title: "test", comment: "test movie")
let documents: Data = try! JSONEncoder().encode([movie])
self.client.addDocuments(
UID: uid,
documents: documents,
primaryKey: nil) { ... }This version of |
|
This is not outdated because they use may want to pass the data directly without the need of writing a |
|
Let's keep both then.
Yes, opening an issue is better! |
curquiza
left a comment
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.
LGTM 👌
|
bors merge |
|
Build succeeded: |
Summary
addDocuments<T>added. Now it's possible to send objects that areCodable/Encodableand the SDK will automatically encode the values to JSON. A custom encoder can be set by addingencoderin the call.Additions
ClientTests.swiftfileLocal tests
Problems
Users are forced to wrap the object to
[]when usingaddDocumentsfunction with objects that areCodable/Encodable. I tried to create a wrapper function for this but Swift doesn't like the direct conversion fromTto[T].