Coder Social home page Coder Social logo

masterbater / prisma-paginate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sandrewtx08/prisma-paginate

0.0 0.0 0.0 1.59 MB

Paginate ORM Prisma

Home Page: https://sandrewtx08.github.io/prisma-paginate/

JavaScript 4.91% TypeScript 95.09%

prisma-paginate's Introduction

๐Ÿ“– prisma-paginate

npm version CI pages-build-deployment

Install

npm i prisma@>=4.9.0 @prisma/client@>=4.9.0 prisma-paginate@latest
yarn add prisma@>=4.9.0 @prisma/client@>=4.9.0 prisma-paginate@latest

โš ๏ธ If you are using the Prisma version equal or greater than >=4.9.0 use clientExtensions preview flag on schema file

prisma/schema.prisma:

generator client {
  provider      = "prisma-client-js"
  previewFeatures = ["clientExtensions"]
}

Documentation and usage

For more details and type definitions see:

http://sandrewtx08.github.io/prisma-paginate/

Importing

// ESM
import { PrismaClient } from "@prisma/client";
import extension from "prisma-paginate";

// Commonjs
const { PrismaClient } = require("@prisma/client");
const { extension } = require("prisma-paginate");

Applying extension

const prisma = new PrismaClient();
const xprisma = prisma.$extends(extension);

xprisma.model2
  .paginate({ limit: 10, page: 1, select: { id: true } })
  .then((result) => {
    console.log(result);
  });

xprisma.table1
  .paginate({ select: { id: true } }, { limit: 10, page: 1 })
  .then((result) => {
    console.log(result);
  });

Paginating 100 rows

// on database = [ { id: 1 }, { id: 2 }, {...}, { id: 100 } ]
xprisma.model1
  .paginate(
    {
      where: {
        // query stuff...
      },
    },
    { page: 1, limit: 50 }
  )
  .then((result) => {
    console.log(result.result); // [ {...}, { id: 48 }, { id: 49 }, { id: 50 } ]
  });

Parameters

  • findManyArgs {Object}
  • paginationArgs {Pagination}

  • findManyPaginationArgs {Object&Pagination}

Return

  • result {Array}
  • totalPages {Number} - Total of pages based on pagination arguments
  • hasNextPage {Boolean} - If has result on next page index
  • hasPrevPage {Boolean} - If has result on last page index
  • count {Number} - Count how many rows on has on table/model with query filter
  • nextPage {Promise} - Request next page
  • exceedCount {Boolean}
  • exceedTotalPages {Boolean}

prisma-paginate's People

Contributors

dependabot[bot] avatar jamesmoss avatar renovate[bot] avatar sandrewtx08 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.