Skip to content

Allow passing 'limit' and 'offset' values as strings #22

Closed
@techniq

Description

@techniq

Currently I am using the following koa route to pass the query string parameters down to js-data-sql

router.get('/races', function*() {
  var options = {};
  if (this.query.with) {
    options.with = Array.isArray(this.query.with) ? this.query.with : [this.query.with];
    delete this.query.with;
  }
  if (this.query.where) {
    this.query.where = JSON.parse(unescape(this.query.where));
  }
  let races = yield db.sql.findAll(models.Race, this.query, options);

  this.body = races;
});

When calling GET /races?limit=3&offset=5, it appears that knex handles limit being passed in as a string (converts it to an int) but not offset.

{ method: 'select',
  options: {},
  bindings: [ 3, '5' ],
  sql: 'select * from `race` limit ? offset ?' }

  Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''5'' at line 1

While I could parse/convert the value in the route, it seemed reasonable to have js-data-sql to handle this simple case (especially with the interplay between js-data-http and js-data-sql). I also took a look at having knex handle this, but I had trouble finding where limit was doing the string/int conversion and felt it was a better fit to have js-data-sql to handle it (because of js-data-http).

Expect an imminent PR for this ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions