Skip to content
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

feat: expands Knex query coverage on models #691

Merged
merged 1 commit into from
May 2, 2017
Merged

feat: expands Knex query coverage on models #691

merged 1 commit into from
May 2, 2017

Conversation

willviles
Copy link
Contributor

@willviles willviles commented Apr 28, 2017

The following PR extends the coverage of Knex query methods available to Lux models.

whereRaw

http://knexjs.org/#Builder-whereRaw

  • Implemented
  • Tests written

Enables the user to build their own where queries. A prime example of the added flexibility this enables is building a scope for fuzzy text searching on columns:

search(request) {
  const whereRaw = Object.keys(request.params.search)
    .reduce(([query, bindings], key, i) => {
      return [
        query += `${i === 0 ? '' : 'AND'} "${key}" LIKE ?`,
        [...bindings, `%${request.params.search[key]}%`]
      ];
    }, ['', []]);

  const [query, bindings] = whereRaw;
  return this.whereRaw(query, bindings);
}

whereBetween / whereNotBetween

http://knexjs.org/#Builder-whereBetween
http://knexjs.org/#Builder-whereNotBetween

  • Implemented
  • Tests written

whereBetween and whereNotBetween are implemented in the same object format as where({}):

Model.whereBetween({
  one: [1, 5],
  two: [1, 5]
});
=> WHERE "model"."one" BETWEEN 1 AND 5 AND "model"."two" BETWEEN 1 AND 5

whereNull / whereNotNull

http://knexjs.org/#Builder-whereNull
http://knexjs.org/#Builder-whereNotNull

  • Implemented
  • Tests written

whereNull is a slight adjustment to the .where({}) query. It simply turns null values into whereNull or whereNotNull snapshots.

@codecov
Copy link

codecov bot commented Apr 28, 2017

Codecov Report

Merging #691 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #691      +/-   ##
==========================================
+ Coverage   92.38%   92.44%   +0.06%     
==========================================
  Files         180      180              
  Lines        1996     2012      +16     
==========================================
+ Hits         1844     1860      +16     
  Misses        152      152
Impacted Files Coverage Δ
src/packages/database/model/index.js 100% <100%> (ø) ⬆️
src/packages/database/query/index.js 94.59% <100%> (+0.56%) ⬆️

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 dd200af...5779fb2. Read the comment docs.

Copy link
Contributor

@zacharygolba zacharygolba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Awesome work!

@zacharygolba zacharygolba merged commit df96fd6 into postlight:master May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants