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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@serdnam/drizzle-orm-utilities

v0.1.3

Published

Miscellaneous helper functions and type utilities for Drizzle ORM

Readme

@serdnam/drizzle-orm-utilities

Miscellaneous helper functions and type utilities for Drizzle ORM.

Disclaimer: This package is an independent community project and is not affiliated with, endorsed by, or maintained by the Drizzle team.


Requirements

  • Node.js >=18.0.0
  • drizzle-orm ^1.0.0-beta.22 (peer dependency)

Installation

npm install @serdnam/drizzle-orm-utilities

drizzle-orm must be installed separately as a peer dependency:

npm install drizzle-orm

Utilities

jsonbBuildObject

Constructs a PostgreSQL jsonb_build_object(...) expression with full TypeScript type inference. The return type is automatically derived from the columns and SQL expressions you pass in, so the result is typed end-to-end without any manual annotation.

Signature

function jsonbBuildObject<T extends Record<string, Column | SQL>>(
  obj: T
): SQL<{ [K in keyof T]: ... }>

Basic usage

import { jsonbBuildObject } from '@serdnam/drizzle-orm-utilities'
import { db } from './db'
import { users } from './schema'

const rows = await db.select({
  summary: jsonbBuildObject({
    id: users.id,
    name: users.name,
  }),
}).from(users)

// rows[0].summary is typed as { id: string; name: string }
console.log(rows[0].summary) // { id: '...', name: 'Alice' }

With SQL expressions

Any SQL value (created with the sql tag) can be used alongside column references. The inferred type comes from the generic you provide to sql<T>.

import { sql } from 'drizzle-orm'
import { jsonbBuildObject } from '@serdnam/drizzle-orm-utilities'

const rows = await db.select({
  data: jsonbBuildObject({
    name: users.name,
    nameUpper: sql<string>`upper(${users.name})`,
  }),
}).from(users)

// rows[0].data is typed as { name: string; nameUpper: string }

Nested calls

jsonbBuildObject returns an SQL expression, so it can be nested inside another call to build deeply structured JSONB objects:

const rows = await db.select({
  data: jsonbBuildObject({
    name: users.name,
    address: jsonbBuildObject({
      city: users.city,
      country: users.country,
    }),
  }),
}).from(users)

// rows[0].data is typed as:
// { name: string; address: { city: string; country: string } }

InferColumnDataType

A type-only utility that extracts the TypeScript data type from a single Drizzle column. Useful when you need the inferred type of a column without going through a full select result.

Signature

type InferColumnDataType<T extends Column> = ...

Usage

import type { InferColumnDataType } from '@serdnam/drizzle-orm-utilities'
import { users } from './schema'

// Extracts the data type of a single column
type UserId = InferColumnDataType<typeof users.id>     // string
type UserName = InferColumnDataType<typeof users.name> // string

// Useful for typing helper functions that accept a column
function logColumn<T extends Column>(col: T, value: InferColumnDataType<T>) {
  console.log(value)
}

Compatibility

The package ships both ESM and CommonJS builds, and works across all modern module resolution strategies.

| Environment | Supported | |---|---| | Node.js ESM (import) | ✅ | | Node.js CJS (require) | ✅ | | Bundlers (Vite, webpack, esbuild) | ✅ | | TypeScript (strict mode) | ✅ | | Drizzle ORM ^1.0.0-beta.22 | ✅ |


Contributing

Integration tests run against a real PostgreSQL database started via Docker Compose.

# Start the database
npm run db:up

# Run migrations
npm run db:migrate

# Run tests
npm test

# Stop the database
npm run db:down

To build the package locally:

npm run build

To validate the package before publishing:

npm run check

License

MIT