@gemcook/pagination-ts
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0 • Public • Published

    pagination-ts

    Example

    make start
    

    Usage

    fetcher type

    fetcher typeを作成する必要があります

    type order = {
      direction: string;
      columnName: string;
    };
     
    type fetcher<T, U> = {
      count(cond: T): number;
      fetchPage(
        cond: T,
        limit: number,
        offset: number,
        orders: order[],
      ): Array<U>;
    };

    Example

    function parseFruitCondition(query) {
      // 
    }
     
    const pagination = Pagination;
    const p = pagintion.parseQuery(req.query);
    const cond = parseFruitCondition(req.query)
     
    const {totalCount, totalPages, pages} = pagination.fetch(fetcher, {
      limit: p.limit,
      page: p.page,
      cond,
      orders: p.sort,
    });
     
    res.setHeader('X-Total-Count', totalCount);
    res.setHeader('X-Total-Pages', totalPages);
    res.json({pages});

    Keywords

    none

    Install

    npm i @gemcook/pagination-ts

    DownloadsWeekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    22.6 kB

    Total Files

    58

    Last publish

    Collaborators

    • k.okayama
    • m.yamashita
    • tfrcm
    • s.nishimura
    • gcshiro