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

drizzle-cuid2

v1.0.5

Published

A utility package for generating CUID2 columns in Drizzle ORM

Downloads

814

Readme

drizzle-cuid2

drizzle-cuid2 is a utility package designed to generate CUIDs (Collision-resistant Unique Identifiers) for use with the Drizzle ORM. This library uses the @paralleldrive/cuid2 package to provide unique and efficient IDs for your database entries.

Table of Contents

Installation

Installing with npm:

npm install drizzle-cuid2

Installing with yarn:

yarn add drizzle-cuid2

Installing with pnpm:

pnpm add drizzle-cuid2

Installing with bun:

bun add drizzle-cuid2

NOTE: This package requires the drizzle-orm package to be installed in your project.

Usage

To use drizzle-cuid2, you will need to import the cuid2 function from the package and use it to define your table columns. The cuid2 function returns a new column definition that can be used with the drizzle-orm package to define your tables.

This package supports the following database types:

Postgres example:

import { pgTable } from 'drizzle-orm/pg-core';
import { cuid2 } from 'drizzle-cuid2/postgres';

export const users = pgTable('doctors', {
  id: cuid2('id').defaultRandom().primaryKey(),
  // other columns...
});

export const posts = pgTable('posts', {
  id: cuid2('id').defaultRandom().primaryKey(),
  userId: cuid2('user_id')
    .notNull()
    .references(() => users.id),
  // other columns...
});

or

import { pgTable } from 'drizzle-orm/pg-core';
import { pgCuid2 } from 'drizzle-cuid2';

export const users = pgTable('doctors', {
  id: pgCuid2('id').defaultRandom().primaryKey(),
  // other columns...
});

export const posts = pgTable('posts', {
  id: pgCuid2('id').defaultRandom().primaryKey(),
  userId: pgCuid2('user_id')
    .notNull()
    .references(() => users.id),
  // other columns...
});

MySQL example:

import { mysqlTable } from 'drizzle-orm/mysql-core';
import { cuid2 } from 'drizzle-cuid2/mysql';

export const users = mysqlTable('doctors', {
  id: cuid2('id').defaultRandom().primaryKey(),
  // other columns...
});

export const posts = mysqlTable('posts', {
  id: cuid2('id').defaultRandom().primaryKey(),
  userId: cuid2('user_id')
    .notNull()
    .references(() => users.id),
  // other columns...
});

or

import { mysqlTable } from 'drizzle-orm/mysql-core';
import { mysqlCuid2 } from 'drizzle-cuid2';

export const users = mysqlTable('doctors', {
  id: mysqlCuid2('id').defaultRandom().primaryKey(),
  // other columns...
});

export const posts = mysqlTable('posts', {
  id: mysqlCuid2('id').defaultRandom().primaryKey(),
  userId: mysqlCuid2('user_id')
    .notNull()
    .references(() => users.id),
  // other columns...
});

SQLite example:

import { sqliteTable } from 'drizzle-orm/sqlite-core';
import { cuid2 } from 'drizzle-cuid2/sqlite';

export const users = sqliteTable('doctors', {
  id: cuid2('id').defaultRandom().primaryKey(),
  // other columns...
});

export const posts = sqliteTable('posts', {
  id: cuid2('id').defaultRandom().primaryKey(),
  userId: cuid2('user_id')
    .notNull()
    .references(() => users.id),
  // other columns...
});

or

import { sqliteTable } from 'drizzle-orm/sqlite-core';
import { sqliteCuid2 } from 'drizzle-cuid2';

export const users = sqliteTable('doctors', {
  id: sqliteCuid2('id').defaultRandom().primaryKey(),
  // other columns...
});

export const posts = sqliteTable('posts', {
  id: sqliteCuid2('id').defaultRandom().primaryKey(),
  userId: sqliteCuid2('user_id')
    .notNull()
    .references(() => users.id),
  // other columns...
});

Issues

If you find a bug or have a feature request, please report them in this repository's issues section.

License

This package is licensed under the MIT license. See the LICENSE file for more information.

Contributing

If you would like to contribute to this project, please refer to the CONTRIBUTING file for more information.

Changelog

Please refer to the CHANGELOG file for a complete list of changes.