Swift-Kuery-ORM icon indicating copy to clipboard operation
Swift-Kuery-ORM copied to clipboard

Add more options in findAll

Open AnthonyAmanse opened this issue 7 years ago • 9 comments
trafficstars

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]

AnthonyAmanse avatar May 30 '18 19:05 AnthonyAmanse

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

:x: djones6
:x: AnthonyAmanse
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar May 30 '18 19:05 CLAassistant

Codecov Report

Merging #38 into master will increase coverage by 0.04%. The diff coverage is 33.33%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#SwiftKueryORM 30.1% <33.33%> (+0.04%) :arrow_up:
Impacted Files Coverage Δ
Sources/SwiftKueryORM/Model.swift 38.36% <33.33%> (-0.15%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9d9618d...3c72ff7. Read the comment docs.

codecov-io avatar May 30 '18 19:05 codecov-io

Hey @AnthonyAmanse, this looks really good! Just a few comments:

  • We have some work planned around QueryParams and filtering so it would be good to just have these options in the findAll calls without QueryParams
  • Some verification needs to take place with the OrderBy parameter to prevent SQL Injection - for example verifying that the column is actually in the table? or using the Parameter() function from SwiftKuery

Thank You

EnriqueL8 avatar May 31 '18 12:05 EnriqueL8

One more suggestion: would be to make the orderBy parameter accept multiple OrderBy instance since for example we would want to order by ascending name and descending age. The definition could be: orderBy: OrderBy? ...

EnriqueL8 avatar May 31 '18 14:05 EnriqueL8

@AnthonyAmanse Sorry - this needs now a rebase since your Swift-Kuery 2.0.0 PR just got merged and addressing the comments

EnriqueL8 avatar Jun 26 '18 08:06 EnriqueL8

@EnriqueL8 No worries. Changes made, used Order instead of OrderBy in functions. Also added a test case if column is not found in table

AnthonyAmanse avatar Jul 03 '18 04:07 AnthonyAmanse

@EnriqueL8 Moved the logic to getOrderBy

AnthonyAmanse avatar Jul 03 '18 18:07 AnthonyAmanse

@EnriqueL8 Feedbacks are always great! Merged the getOrderBy function instead of overloading. Sorted the rows using rows.sort instead of hardcoding it.

AnthonyAmanse avatar Jul 13 '18 15:07 AnthonyAmanse

LGTM - Updated Branch because it is out-of-date Needs a Squash

EnriqueL8 avatar Jul 18 '18 08:07 EnriqueL8