How to use the webiny-entity.createPaginationMeta function in webiny-entity

To help you get started, we’ve selected a few webiny-entity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / webiny-entity-mongodb / src / MongoDbDriver.js View on Github external
MongoDbDriver.__prepareSearchOption(clonedOptions);

        // Get first documents from cursor using each
        const results = await this.getDatabase()
            .collection(this.getCollectionName(entity))
            .find(clonedOptions.query)
            .limit(clonedOptions.limit)
            .skip(clonedOptions.offset)
            .sort(clonedOptions.sort)
            .toArray();

        const totalCount = await this.getDatabase()
            .collection(this.getCollectionName(entity))
            .countDocuments(clonedOptions.query);

        const meta = createPaginationMeta({
            totalCount,
            page: options.page,
            perPage: options.perPage
        });

        return new QueryResult(results, meta);
    }
github webiny / webiny-js / packages / webiny-api-page-builder / src / plugins / graphql / pageResolvers / listPublishedPages.js View on Github external
aggregation: async ({ aggregate, QueryResult }) => {
            const pipelines = {
                results: pipeline.concat({ $skip: (page - 1) * perPage }, { $limit: perPage }),
                totalCount: pipeline.concat({
                    $count: "count"
                })
            };

            const results = (await aggregate(pipelines.results)) || [];
            const totalCount = get(await aggregate(pipelines.totalCount), "0.count") || 0;

            const meta = createPaginationMeta({
                totalCount,
                page,
                perPage
            });

            return new QueryResult(results, meta);
        }
    });
github webiny / webiny-js / packages / webiny-api-page-builder / src / plugins / graphql / pageResolvers / listPages.js View on Github external
...pipeline,
            { $project: { _id: -1, id: 1 } },
            { $skip: (page - 1) * perPage },
            { $limit: perPage }
        ]);

    const [totalCount] = await entityClass.getDriver().aggregate(collection, [
        ...pipeline,
        {
            $count: "totalCount"
        }
    ]);

    return new ListResponse(
        await entityClass.find({ sort, query: { id: { $in: ids.map(item => item.id) } } }),
        createPaginationMeta({
            page,
            perPage,
            totalCount: totalCount ? totalCount.totalCount : 0
        })
    );
};
github webiny / webiny-js / packages / webiny-entity-mysql / src / mysqlDriver.js View on Github external
operation: "select",
            limit: 10,
            offset: 0
        });

        MySQLDriver.__preparePerPageOption(clonedOptions);
        MySQLDriver.__preparePageOption(clonedOptions);
        MySQLDriver.__prepareQueryOption(clonedOptions);
        MySQLDriver.__prepareSearchOption(clonedOptions);

        clonedOptions.calculateFoundRows = true;

        const sql = new Select(clonedOptions, entity).generate();
        const results = await this.getConnection().query([sql, "SELECT FOUND_ROWS() as count"]);

        const meta = createPaginationMeta({
            totalCount: results[1][0].count,
            page: options.page,
            perPage: options.perPage
        });

        return new QueryResult(results[0], meta);
    }