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

@icetype/drizzle

v0.3.0

Published

IceType adapter for Drizzle ORM - generates Drizzle schema files from IceType schemas

Downloads

10

Readme

@icetype/drizzle

Drizzle ORM adapter for IceType schema transformations. This package generates Drizzle ORM schema files from IceType schemas, supporting PostgreSQL, MySQL, and SQLite dialects. It also supports importing existing Drizzle schemas into IceType format.

Installation

npm install @icetype/drizzle
# or
pnpm add @icetype/drizzle

Usage

import { parseSchema } from '@icetype/core';
import { DrizzleAdapter, transformToDrizzle } from '@icetype/drizzle';

// Parse an IceType schema
const schema = parseSchema({
  $type: 'User',
  id: 'uuid!',
  email: 'string#',
  name: 'string',
  age: 'int?',
  createdAt: 'timestamp',
});

// Option 1: Use the adapter directly
const adapter = new DrizzleAdapter();
const drizzleSchema = adapter.transform(schema, { dialect: 'pg' });
const code = adapter.serialize(drizzleSchema);

// Option 2: Use the convenience function
const code2 = transformToDrizzle(schema, { dialect: 'pg' });

console.log(code2);
// Output:
// import { pgTable, uuid, varchar, integer, timestamp } from 'drizzle-orm/pg-core';
//
// export const users = pgTable('users', {
//   id: uuid('id').primaryKey().notNull(),
//   email: varchar('email', { length: 255 }).notNull().unique(),
//   name: varchar('name', { length: 255 }),
//   age: integer('age'),
//   createdAt: timestamp('createdAt'),
// });
//
// export type Users = typeof users.$inferSelect;
// export type NewUsers = typeof users.$inferInsert;

API

Main Exports

| Export | Description | |--------|-------------| | DrizzleAdapter | Adapter class for Drizzle schema generation | | createDrizzleAdapter() | Factory function to create adapter | | transformToDrizzle(schema, options) | Transform schema to Drizzle code string | | generateDrizzleSchema(schema, options) | Generate Drizzle schema object | | transformSchemasToDrizzle(schemas, options) | Transform multiple schemas |

Types

| Type | Description | |------|-------------| | DrizzleDialect | Dialect type ('pg', 'mysql', 'sqlite') | | DrizzleColumn | Column definition for Drizzle | | DrizzleIndex | Index definition | | DrizzleTable | Table definition | | DrizzleSchema | Complete schema structure | | DrizzleImport | Import statement structure | | DrizzleAdapterOptions | Options for schema generation | | DrizzleTypeMapping | Type mapping configuration | | DrizzleTypeMappings | All type mappings by dialect |

Type Mapping Utilities

| Export | Description | |--------|-------------| | DRIZZLE_TYPE_MAPPINGS | Type mappings for all dialects | | getDrizzleType(iceType, dialect) | Get Drizzle type for IceType | | getDrizzleImportPath(dialect) | Get import path for dialect | | getTableFunction(dialect) | Get table function name (pgTable, etc.) | | isKnownDrizzleType(type) | Check if type is known | | getRequiredTypeImports(columns) | Get required imports for columns |

Code Generation Utilities

| Export | Description | |--------|-------------| | toCamelCase(str) | Convert to camelCase | | toSnakeCase(str) | Convert to snake_case | | toPascalCase(str) | Convert to PascalCase | | escapeString(str) | Escape string for code | | generateImports(schema) | Generate import statements | | collectImports(tables) | Collect all required imports | | generateColumn(column) | Generate column definition code | | generateTable(table) | Generate table definition code | | generateSchemaCode(schema) | Generate complete schema code | | formatDefaultValue(value) | Format default value | | validateTableName(name) | Validate table name | | validateColumnName(name) | Validate column name |

Importer (Drizzle to IceType)

| Export | Description | |--------|-------------| | parseDrizzleSchema(code) | Parse Drizzle code to IceType schemas | | parseDrizzleFile(path) | Parse Drizzle file to IceType schemas | | parseRawTables(code) | Parse raw table definitions | | getIceTypeFromDrizzle(drizzleType) | Convert Drizzle type to IceType | | detectDialect(code) | Detect dialect from code | | parseColumn(code) | Parse single column definition | | columnToFieldDefinition(column) | Convert column to IceType field | | tableToIceTypeSchema(table) | Convert table to IceType schema |

Importer Types

| Type | Description | |------|-------------| | DrizzleImportOptions | Options for importing | | ParsedDrizzleColumn | Parsed column structure | | ParsedDrizzleTable | Parsed table structure |

Examples

PostgreSQL Schema

import { parseSchema } from '@icetype/core';
import { transformToDrizzle } from '@icetype/drizzle';

const schema = parseSchema({
  $type: 'Product',
  id: 'uuid!',
  name: 'string!',
  price: 'decimal(10,2)!',
  stock: 'int!',
  tags: 'string[]',
  metadata: 'json?',
});

const code = transformToDrizzle(schema, { dialect: 'pg' });

MySQL Schema

const code = transformToDrizzle(schema, { dialect: 'mysql' });
// Uses mysqlTable, varchar, int, etc.

SQLite Schema

const code = transformToDrizzle(schema, { dialect: 'sqlite' });
// Uses sqliteTable, text, integer, etc.

Multiple Schemas

import { parseSchema } from '@icetype/core';
import { transformSchemasToDrizzle } from '@icetype/drizzle';

const userSchema = parseSchema({
  $type: 'User',
  id: 'uuid!',
  email: 'string!',
  name: 'string',
});

const postSchema = parseSchema({
  $type: 'Post',
  id: 'uuid!',
  title: 'string!',
  authorId: 'uuid!',
});

const code = transformSchemasToDrizzle([userSchema, postSchema], {
  dialect: 'pg',
});

Import Existing Drizzle Schema

import { parseDrizzleSchema, parseDrizzleFile } from '@icetype/drizzle';

// Parse from string
const schemas = parseDrizzleSchema(`
  import { pgTable, uuid, varchar } from 'drizzle-orm/pg-core';

  export const users = pgTable('users', {
    id: uuid('id').primaryKey().notNull(),
    email: varchar('email', { length: 255 }).notNull().unique(),
    name: varchar('name', { length: 255 }),
  });
`);

// Parse from file
const fileSchemas = await parseDrizzleFile('./drizzle/schema.ts');

console.log(schemas);
// [{ $type: 'users', id: 'uuid!', email: 'string!#', name: 'string?' }]

Using with Adapter Registry

import { createAdapterRegistry } from '@icetype/adapters';
import { DrizzleAdapter } from '@icetype/drizzle';

const registry = createAdapterRegistry();
registry.register(new DrizzleAdapter());

const adapter = registry.get('drizzle');
const drizzleSchema = adapter?.transform(schema, { dialect: 'pg' });
const code = adapter?.serialize(drizzleSchema);

Type Mappings by Dialect

PostgreSQL (pg)

| IceType | Drizzle Type | |---------|--------------| | string | varchar | | text | text | | int | integer | | bigint | bigint | | float | real | | double | doublePrecision | | boolean | boolean | | uuid | uuid | | timestamp | timestamp | | date | date | | json | jsonb | | decimal | decimal |

MySQL

| IceType | Drizzle Type | |---------|--------------| | string | varchar | | text | text | | int | int | | bigint | bigint | | float | float | | double | double | | boolean | boolean | | uuid | varchar(36) | | timestamp | timestamp | | date | date | | json | json | | decimal | decimal |

SQLite

| IceType | Drizzle Type | |---------|--------------| | string | text | | text | text | | int | integer | | bigint | integer | | float | real | | double | real | | boolean | integer | | uuid | text | | timestamp | integer | | date | text | | json | text |

Documentation

For full documentation, visit the IceType Documentation.

Related Packages

License

MIT