Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphile-contrib/pg-order-by-multi-column-index
Order by multi-column indexes on PostGraphile connections
https://github.com/graphile-contrib/pg-order-by-multi-column-index
Last synced: 12 days ago
JSON representation
Order by multi-column indexes on PostGraphile connections
- Host: GitHub
- URL: https://github.com/graphile-contrib/pg-order-by-multi-column-index
- Owner: graphile-contrib
- License: mit
- Created: 2018-11-27T13:27:09.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-01T11:36:31.000Z (5 months ago)
- Last Synced: 2024-09-19T18:48:52.143Z (about 2 months ago)
- Language: JavaScript
- Size: 431 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @graphile-contrib/pg-order-by-multi-column-index
[![Package on npm](https://img.shields.io/npm/v/@graphile-contrib/pg-order-by-multi-column-index.svg)](https://www.npmjs.com/package/@graphile-contrib/pg-order-by-multi-column-index)
This Graphile Engine plugin adds enum values to the `orderBy` argument on connections, allowing you to order by multi-column indexes.
> Requires `postgraphile@^4.1.0` or `graphile-build-pg@^4.1.0`
> NOTE: If you're not using `ignoreIndexes: false`, then you probably don't need this plugin.
PostGraphile's `ignoreIndexes: false` option only exposes the first column of each multi-column index on `orderBy`. This prevents clients from sending queries with an array of column names/directions that can't make use of the multi-column index. This plugin adds enum values to `orderBy` that match forward and backward scans of the index.
Example:
```sql
create index on p.person (last_name ASC, first_name ASC);
``````graphql
{
allPeople(orderBy: LAST_NAME_ASC__FIRST_NAME_ASC) {
nodes {
id
firstName
lastName
}
}
}
```## Usage
Append this plugin and the additional `orderBy` enum values will be added to your schema.
### CLI
```bash
yarn add postgraphile
yarn add @graphile-contrib/pg-order-by-multi-column-index
npx postgraphile --append-plugins @graphile-contrib/pg-order-by-multi-column-index
```### Library
```js
const express = require("express");
const { postgraphile } = require("postgraphile");
const PgOrderByMultiColumnIndexPlugin = require("@graphile-contrib/pg-order-by-multi-column-index");const app = express();
app.use(
postgraphile(process.env.DATABASE_URL, "app_public", {
appendPlugins: [PgOrderByMultiColumnIndexPlugin],
graphiql: true,
})
);app.listen(5000);
```