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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@drizzle-adapter/pg-core

v1.0.15

Published

Shared PostgreSQL functionality for the Drizzle Adapter ecosystem.

Downloads

50

Readme

@drizzle-adapter/pg-core

Shared PostgreSQL functionality for the Drizzle Adapter ecosystem.

Overview

The @drizzle-adapter/pg-core package provides shared PostgreSQL functionality used by PostgreSQL-compatible adapters in the Drizzle Adapter ecosystem. This package is an internal dependency used by:

Purpose

This package standardizes PostgreSQL-specific functionality across different PostgreSQL-compatible adapters:

  • Common PostgreSQL data type definitions
  • Shared PostgreSQL query building logic
  • Unified PostgreSQL error handling
  • Common PostgreSQL utility functions

Installation

# This package is typically not installed directly but as a dependency of PostgreSQL adapters
pnpm install @drizzle-adapter/pg-core

For Adapter Developers

If you're developing a new PostgreSQL-compatible adapter for the Drizzle Adapter ecosystem, you should use this package to ensure consistency with other PostgreSQL adapters:

import { PostgresDrizzleDataTypes } from '@drizzle-adapter/pg-core';

export class YourPostgresAdapter implements DrizzleAdapterInterface {
  public getDataTypes(): PostgresDrizzleDataTypes {
    return new PostgresDrizzleDataTypes();
  }
  
  // ... rest of your adapter implementation
}

Data Types

The package provides standardized PostgreSQL data type definitions:

const dataTypes = new PostgresDrizzleDataTypes();

const table = dataTypes.dbTable('example', {
  // Numeric types
  id: dataTypes.dbSerial('id').primaryKey(),
  count: dataTypes.dbInteger('count'),
  price: dataTypes.dbDecimal('price', { precision: 10, scale: 2 }),
  
  // String types
  name: dataTypes.dbText('name'),
  description: dataTypes.dbText('description'),
  
  // Date/Time types
  createdAt: dataTypes.dbTimestampTz('created_at').defaultNow(),
  updatedAt: dataTypes.dbTimestampTz('updated_at').onUpdateNow(),
  
  // PostgreSQL-specific types
  tags: dataTypes.dbArray('tags', { type: 'text' }),
  metadata: dataTypes.dbJsonb('metadata'),
  searchVector: dataTypes.dbTsVector('search_vector'),
  status: dataTypes.dbEnum('status', ['active', 'inactive']),
  point: dataTypes.dbPoint('location'),
  range: dataTypes.dbRange('valid_period', { type: 'timestamp' })
});

Error Handling

The package provides unified error handling for PostgreSQL-specific errors:

import { handlePostgresError } from '@drizzle-adapter/pg-core';

try {
  // Your database operation
} catch (error) {
  throw handlePostgresError(error);
}

Query Building

The package includes utilities for building PostgreSQL-specific queries:

import { 
  buildInsertQuery,
  buildUpdateQuery,
  buildDeleteQuery,
  buildSelectQuery,
  buildFullTextSearchQuery
} from '@drizzle-adapter/pg-core';

// Build INSERT query
const insertQuery = buildInsertQuery(table, data);

// Build UPDATE query with JSONB operations
const updateQuery = buildUpdateQuery(table, {
  metadata: sql`${table.metadata} || '{"key": "value"}'::jsonb`
});

// Build DELETE query with conditions
const deleteQuery = buildDeleteQuery(table, conditions);

// Build SELECT query with joins
const selectQuery = buildSelectQuery({
  table,
  joins: [...],
  conditions: [...],
  orderBy: [...]
});

// Build full-text search query
const searchQuery = buildFullTextSearchQuery({
  table,
  columns: ['title', 'content'],
  searchTerm: 'search term',
  language: 'english'
});

Type Mapping

The package handles PostgreSQL-specific type mapping:

import { mapPostgresType } from '@drizzle-adapter/pg-core';

// Map JavaScript types to PostgreSQL types
const pgType = mapPostgresType(value);

// Map PostgreSQL types to JavaScript types
const jsValue = mapToJavaScript(pgValue, pgType);

// Handle array types
const arrayType = mapArrayType(elementType);

// Handle range types
const rangeType = mapRangeType(boundType);

PostgreSQL-Specific Features

import { 
  createTsVector,
  createGinIndex,
  handleArrayOperations,
  handleJsonbOperations
} from '@drizzle-adapter/pg-core';

// Create tsvector column
const tsVectorSQL = createTsVector(['title', 'content'], 'english');

// Create GIN index for full-text search
const indexSQL = createGinIndex('posts_search_idx', 'posts', 'search_vector');

// Handle array operations
const arrayCondition = handleArrayOperations(column, operator, values);

// Handle JSONB operations
const jsonbCondition = handleJsonbOperations(column, path, value);

Contributing

This package is maintained as part of the Drizzle Adapter ecosystem. If you'd like to contribute:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Related Packages