-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add more options in findAll #38
base: master
Are you sure you want to change the base?
Conversation
|
Codecov Report
@@ Coverage Diff @@
## master #38 +/- ##
=========================================
+ Coverage 30.05% 30.1% +0.04%
=========================================
Files 6 6
Lines 1364 1385 +21
=========================================
+ Hits 410 417 +7
- Misses 954 968 +14
Continue to review full report at Codecov.
|
Hey @AnthonyAmanse, this looks really good! Just a few comments:
Thank You |
One more suggestion: would be to make the |
65a9655
to
3c72ff7
Compare
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.
@EnriqueL8 Thanks for the feedback. Updated the function to accept a variadic parameter of orderBy
. Not sure what to do with verification for columns though
var column: Column? | ||
do { | ||
let table = try Person.getTable() | ||
column = table.columns.first(where: {$0.name == "age"}) |
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.
@EnriqueL8 Would this be enough for a verification if the column exists? Since the orderBy
parameter is an OrderBy buildable that doesn't accept just any string, verification would have to be done outside of findAll
function
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.
XCTAssertNil(error, "Find Failed: \(String(describing: error))") | ||
} | ||
performTest(asyncTasks: { expectation in | ||
Person.findAll(orderBy: OrderBy.DESC(column!)) { array, error 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.
This need to be .ASC
@AnthonyAmanse Sorry - this needs now a rebase since your Swift-Kuery 2.0.0 PR just got merged and addressing the comments |
3c72ff7
to
ff27ca9
Compare
@EnriqueL8 No worries. Changes made, used |
Sources/SwiftKueryORM/Model.swift
Outdated
let query = Select(from: table) | ||
var query = Select(from: table) | ||
var orderByArray: [OrderBy] = [] | ||
for order in order { |
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 extract this logic into a function?
ff27ca9
to
3a898b7
Compare
@EnriqueL8 Moved the logic to |
Sources/SwiftKueryORM/Model.swift
Outdated
/** | ||
This function constructs an array of OrderBy from the Order values | ||
*/ | ||
private static func getOrderBy(order: [Order], table: Table) throws -> [OrderBy] { |
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.
This method looks quite familiar to the above method, maybe we could call this method from the above to remove code duplication
Sources/SwiftKueryORM/Model.swift
Outdated
var orderByArray: [OrderBy] = [] | ||
for order in order { | ||
guard let column = table.columns.first(where: {$0.name == order.value}) else { | ||
throw RequestError(.ormInternalError, reason: "Column \(order.value) not found") |
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.
Instead of throwing an .ormInternalError
, we should throw .ormQueryError
because it failed during the construction of the Query?
Sources/SwiftKueryORM/Model.swift
Outdated
guard let column = table.columns.first(where: {$0.name == order.value}) else { | ||
throw RequestError(.ormInternalError, reason: "Column \(order.value) not found") | ||
} | ||
if case .asc(order.value) = order { |
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.
Can we remove the order.value
? And just have .asc(_)
?
self.numberOfRows = numberOfRows | ||
if let sortedByAge = sortedByAge { |
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 we sort the array programatically? By using array.sort
? In the case of having to change the rows we would also have to update these two lines.
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.
Sorry - I promise these are the last changes that I suggest!
3a898b7
to
a03ea46
Compare
@EnriqueL8 Feedbacks are always great! Merged the |
LGTM - Updated Branch because it is out-of-date |
This commit adds in options: * ORDER BY clause for sorting * OFFSET and LIMIT for retrieving a portion of the rows This builds the appropriate SQL queries for the options listed above. This commit also adds in initial tests for the new options. Signed-off-by: AnthonyAmanse <[email protected]>
2ea13b7
to
f285773
Compare
This commit adds in options:
This builds the appropriate SQL queries for the options listed above.
This commit also adds in initial tests for the new options.
Signed-off-by: AnthonyAmanse [email protected]