o1lab/xmysql

Disable maximum

Parilar opened this issue · 6 comments

Hey,
is there a way to disable the maximum ?
Why is there a maximum of 100

Indeed

  • the maximum size of a request is 100 rows
  • there isn't an option to download all rows at the same time.
  • I am looking for an option ( I did not find it ) to know how much pages I have in a request for a certain amount of selected rows size

How can we solve?

o1lab commented

Currently, there is no way to know number of pages. Can be a feature going ahead.
As a work around you can call api to know count and work the number of pages if its absolutely required.

API returns 20 objects by default, just make count / 20 to know how many pages you have :)

Bnaya commented

I've monkeypatched Xsql to overcome that hardcoded limit for my usecase

const MAX_ROWS = 10000;

// monkeypatch overwrite 100 limit :)
Xsql.prototype.getLimitClause = function getLimitClause(reqParams: any) {
    reqParams._index = 0;
    reqParams._len = 20;

    if ("_size" in reqParams) {
        if (parseInt(reqParams._size) > 0 && parseInt(reqParams._size) <= MAX_ROWS) {
            reqParams._len = parseInt(reqParams._size);
        } else if (parseInt(reqParams._size) > MAX_ROWS) {
            reqParams._len = MAX_ROWS;
        }
    }

    if ("_p" in reqParams && parseInt(reqParams._p) > 0) {
        reqParams._index = (parseInt(reqParams._p) - 1) * reqParams._len;
    }

    //console.log(reqParams._index, reqParams._len);

    return [reqParams._index, reqParams._len];
};

Try it
not very optim for front

 getTableByEntytiWhere(entity, whereField,likeField) {
    return new Promise<any>((resolve, reject) => {
      let resultTable = [];
      this.http.get(this.apiUrl + "locations/" + entity + "/count?_where=("+whereField+",like,"+likeField+")").subscribe(async (res) => {
        let loops = Math.trunc(parseInt(res[0].no_of_rows) / 100) + 1;
        for (let index = 0; index < loops; index++) {
          let resultQuery = await new Promise<any>((resolve, reject) => { this.http.get(this.apiUrl + "locations/" + entity + "?_where=("+whereField+",like,"+likeField+")&_p=" + index + "&_size=100").subscribe((res)=>resolve(res),(err)=>{reject(err)})});
          resultQuery.forEach(element => {
            resultTable.push(element);
          });
         ;
        }
        resolve(resultTable);
      });
    });
  }

Any news on this one? I'm hitting this as well. One thing to note is that query I'm using does a descending sort and the arbitrary objects returned in the first 20 will be sorted, but they do not represent the top 20 sorted rows of the entire set.
eg for a row with a field vid set to an int, and the entire set is vid=[1..30], my sorted query might return 5 as the lowest and 25 as the highest, and the results vary for the same repeated request