npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@keystone-alpha/fields-auto-increment

v2.0.5

Published

KeystoneJS AutoIncrement Field Type

Downloads

120

Readme

AutoIncrement

An automatically incrementing integer with support for the Knex adapter. It's important to note, this type..

Currently, outside its use as a primary key, this field type will only work on PostgreSQL.

Limitations

The majority of DB platforms allow only a single automatically incrementing column per table. At time of writing (2019-07-11) this is true of SQLite, MySQL, SQL Server, Oracle, and MariaDB. Further, it is often assumed these columns are the tables primary key. On several platforms (eg. SQLite) auto increment functionality is only available for primary keys.

Of the DB platforms supported by Knex, only PostgreSQL and Amazon Redshift supports multiple auto incrementing columns.

Non-Standard Defaults

The configuration for AutoIncrement fields has different default values than most field types. Specifically:

  • isUnique defaults to true -- As unique values are generated by the DB it's assumed this uniqueness should be enforced with a unique constraint.
  • isNotNullable defaults to true -- Likewise, it's assumed values will never be updated or explicitly set to null. The column is set to be not nullable to enforce this.
  • Read only -- It's assumed AutoIncrement are not intended to be writable. Some DB platform will error if you attempt to update columns created by this type. Further, if the column has a unique constraint (as is the default; see isUnique in config above) inserting arbitrary values may cause errors when later records are created. As such, fields using this type default to being read-only. This is implemented by defaulting the create, update and delete field-level access control config to false.

Usage

const { Keystone } = require('@keystone-alpha/keystone');
const { AutoIncrement } = require('@keystone-alpha/fields-auto-increment');

const keystone = new Keystone(/* ... */);

keystone.createList('Order', {
  fields: {
    name: { type: Text },
    orderNumber: { type: AutoIncrement, gqlType: 'Int' },
    // ...
  },
});

Config

| Option | Type | Default | Description | | :----------- | :-------- | :------------ | :------------------------------------------------------------------------------------------ | | isRequired | Boolean | false | Does this field require a value? | | isUnique | Boolean | true | Adds a unique index that allows only unique values to be stored | | gqlType | String | Int or ID | The GraphQL to be used by this field. Defaults to ID for primary keys or Int otherwise. |

Admin UI

AutoIncrement fields reuse the interface implementation from the native Integer field.

GraphQL

AutoIncrement fields can use the Int or ID GraphQL types. This can be specified using the gqlType config option if needed. The default is ID for primary key fields and Int otherwise.

Input Fields

AutoIncrement fields are read-only by default. As such, input fields and types may not be added to the GraphQL schema. See the non-standard defaults section for details.

| Field name | Type | Description | | :--------- | :------------ | :------------------------ | | ${path} | Int or ID | The integer value to save |

Output Fields

| Field name | Type | Description | | :--------- | :------------ | :----------------------- | | ${path} | Int or ID | The integer value stored |

Filters

| Field name | Type | Description | | :--------------- | :---------------- | :------------------------------------------ | | ${path} | Int or ID | Exact match to the value provided | | ${path}_not | Int or ID | Not an exact match to the value provided | | ${path}_lt | Int or ID | Less than the value provided | | ${path}_lte | Int or ID | Less than or equal to the value provided | | ${path}_gt | Int or ID | Greater than the value provided | | ${path}_gte | Int or ID | Greater or equal to than the value provided | | ${path}_in | [Int] or [ID] | In the array of integers provided | | ${path}_not_in | [Int] or [ID] | Not in the array of integers provided |

Storage

Knex Adapter

The AutoIncrement field type uses increments() by default. The underlying implementation varies in significant ways depending on the DB platform used (see limitations).

One implication of increments() is that Knex will always make it the primary key of the table. To work around this, if this type is not being used as the lists primary key, we replace the generic increments() call with an explicitly build serial column. This work around only supports PostgreSQL; on other DB platforms, this type can only be used for the id field. See the Limitations section more about auto inc and their usage as primary keys.

Mongoose Adapter

Not supported.