JSPM

dreeked

1.1.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 4
    • Score
      100M100P100Q27002F
    • License MIT

    AI-powered CLI tool to generate ORM schemas from PostgreSQL and MySQL databases

    Package Exports

    • dreeked
    • dreeked/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dreeked) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Insomma CLI Tool

    AI-powered CLI tool to generate ORM schemas from PostgreSQL and MySQL databases using advanced language models.

    Features

    • Multi-Database Support: Works with both PostgreSQL and MySQL databases
    • Multi-ORM Support: Generate schemas for Prisma, TypeORM, Drizzle, and Zod
    • Complete Metadata Extraction: Tables, columns, relationships, indexes, enums, and constraints
    • AI-Powered Generation: Uses Meta's Llama 3.3 70B model via DeepInfra
    • Auto-Detection: Automatically detects database type from connection string
    • Flexible Output: Write to file or output to stdout
    • Connection Testing: Verify database connectivity before processing
    • Comprehensive CLI: Multiple commands for different use cases

    Installation

    Global Installation

    npm install -g insomma

    Run with npx

    npx insomma --help

    Run with bunx

    bunx insomma --help

    Setup

    Get DeepInfra API Key

    1. Sign up at DeepInfra
    2. Get your API key from the dashboard
    3. Set it as an environment variable or pass it as an option
    export DEEPINFRA_API_KEY="your-api-key-here"

    Usage

    PostgreSQL Examples

    Basic Schema Generation

    insomma \
      --connection "postgres://user:password@localhost:5432/mydb" \
      --orm prisma \
      --output schema.prisma

    Generate TypeORM Entities

    insomma \
      --connection "postgres://user:pass@host:port/db" \
      --orm typeorm \
      --output entities.ts

    MySQL Examples

    Basic Schema Generation

    insomma \
      --connection "mysql://user:password@localhost:3306/mydb" \
      --orm prisma \
      --output schema.prisma

    Generate Drizzle Schema

    insomma \
      --connection "mysql://user:pass@host:port/db" \
      --orm drizzle \
      --output schema.ts

    Universal Examples

    Generate Zod Validation Schemas

    insomma \
      --connection "postgres://user:pass@host:port/db" \
      --orm zod \
      --output validations.ts

    Output to Console

    insomma \
      --connection "mysql://user:pass@host:port/db" \
      --orm prisma

    Specify Database Type Explicitly

    insomma \
      --connection "some-custom-connection-string" \
      --type mysql \
      --orm prisma

    Test Database Connection

    # Auto-detect database type
    insomma test-connection \
      --connection "postgres://user:pass@host:port/db"
    
    # Specify database type
    insomma test-connection \
      --connection "mysql://user:pass@host:port/db" \
      --type mysql

    List Database Tables

    # PostgreSQL
    insomma list-tables \
      --connection "postgres://user:pass@host:port/db"
    
    # MySQL
    insomma list-tables \
      --connection "mysql://user:pass@host:port/db"

    Command Options

    Main Command

    • -c, --connection <string> - Database connection string (required)
    • -t, --type <string> - Database type (postgres, mysql, auto) [default: auto]
    • -o, --orm <string> - Target ORM (prisma, typeorm, drizzle, zod) [default: prisma]
    • -f, --output <string> - Output file path (optional)
    • --api-key <string> - DeepInfra API key (optional if env var set)
    • --verbose - Enable verbose logging

    Test Connection Command

    • -c, --connection <string> - Database connection string (required)
    • -t, --type <string> - Database type (postgres, mysql, auto) [default: auto]

    List Tables Command

    • -c, --connection <string> - Database connection string (required)
    • -t, --type <string> - Database type (postgres, mysql, auto) [default: auto]

    Connection String Formats

    PostgreSQL

    postgres://username:password@hostname:port/database
    postgresql://username:password@hostname:port/database

    Examples:

    # Local database
    postgres://postgres:password@localhost:5432/myapp
    
    # Remote database
    postgres://user:pass@db.example.com:5432/production
    
    # With SSL
    postgres://user:pass@host:5432/db?sslmode=require

    MySQL

    mysql://username:password@hostname:port/database

    Examples:

    # Local database
    mysql://root:password@localhost:3306/myapp
    
    # Remote database
    mysql://user:pass@db.example.com:3306/production
    
    # With SSL
    mysql://user:pass@host:3306/db?ssl=true

    Database Type Detection

    The tool automatically detects the database type from the connection string:

    • PostgreSQL: Detected by postgres://, postgresql:// prefixes or port :5432
    • MySQL: Detected by mysql:// prefix or port :3306
    • Manual Override: Use --type option to specify explicitly

    Supported ORMs

    Prisma

    Generates complete Prisma schema with:

    • Generator and datasource blocks (PostgreSQL/MySQL specific)
    • Proper data type mappings for each database
    • Relationships with @relation
    • Constraints and indexes
    • Database-specific features

    TypeORM

    Generates TypeScript entity classes with:

    • Proper decorators (@Entity, @Column, etc.)
    • Database-specific type mappings
    • Relationship definitions
    • Column constraints
    • Auto-increment handling

    Drizzle

    Generates Drizzle schema with:

    • Database-specific imports (pg-core/mysql-core)
    • Table definitions using pgTable/mysqlTable
    • Proper column types for each database
    • Foreign key relationships
    • Constraints and indexes

    Zod

    Generates validation schemas with:

    • Type-safe validations
    • Database-appropriate Zod types
    • Optional/required field handling
    • Custom validations
    • Database-specific field handling

    Examples by Database

    E-commerce PostgreSQL to Prisma

    insomma \
      --connection "postgres://admin:secret@localhost:5432/ecommerce" \
      --orm prisma \
      --output prisma/schema.prisma \
      --verbose

    Blog MySQL to TypeORM

    insomma \
      --connection "mysql://blogger:pass123@blog-db:3306/blog" \
      --orm typeorm \
      --output src/entities/index.ts

    Analytics PostgreSQL to Drizzle

    insomma \
      --connection "postgres://analyst:data@analytics.internal:5432/metrics" \
      --orm drizzle \
      --output lib/schema.ts

    CRM MySQL to Zod

    insomma \
      --connection "mysql://crm:secure@crm.company.com:3306/customer_data" \
      --orm zod \
      --output lib/validations.ts

    Metadata Extraction

    The tool extracts comprehensive database metadata including:

    PostgreSQL

    • Tables: Names, schemas, comments
    • Columns: Data types, constraints, defaults, comments
    • Relationships: Foreign keys with cascade rules
    • Indexes: Custom indexes (excluding primary keys)
    • Enums: PostgreSQL enum types and values
    • Constraints: Primary keys, unique constraints, check constraints

    MySQL

    • Tables: Names, schemas, comments
    • Columns: Data types, constraints, defaults, comments, auto-increment
    • Relationships: Foreign keys with cascade rules
    • Indexes: Custom indexes (excluding primary keys)
    • Enums: ENUM and SET column types
    • Constraints: Primary keys, unique constraints

    Database-Specific Features

    PostgreSQL Features

    • Full schema support
    • Custom enum types
    • Advanced constraint types
    • UUID and serial types
    • JSONB support

    MySQL Features

    • Auto-increment columns
    • ENUM and SET types
    • Unsigned integer types
    • MySQL-specific data types
    • Storage engine considerations

    Error Handling

    The tool provides clear error messages for:

    • Invalid connection strings
    • Unsupported database types
    • Network connectivity issues
    • API authentication problems
    • Unsupported database features
    • File system permissions

    Troubleshooting

    Connection Issues

    # Test your connection first
    insomma test-connection --connection "your-connection-string"
    
    # Specify database type if auto-detection fails
    insomma test-connection --connection "your-connection-string" --type mysql

    Database Type Detection Issues

    # Force database type
    insomma --type postgres --connection "..." --orm prisma
    insomma --type mysql --connection "..." --orm prisma

    API Key Issues

    # Verify your API key is set
    echo $DEEPINFRA_API_KEY
    
    # Or pass it directly
    insomma --api-key "your-key" --connection "..." --orm prisma

    Verbose Logging

    # Enable verbose output for debugging
    insomma --verbose --connection "..." --orm prisma

    Requirements

    • Node.js 16 or higher
    • PostgreSQL or MySQL database access
    • DeepInfra API key
    • Internet connection for AI generation

    Supported Database Versions

    PostgreSQL

    • PostgreSQL 10+
    • All major cloud providers (AWS RDS, Google Cloud SQL, Azure Database)

    MySQL

    • MySQL 5.7+
    • MySQL 8.0+
    • MariaDB 10.3+
    • All major cloud providers (AWS RDS, Google Cloud SQL, Azure Database)

    License

    MIT License - see LICENSE file for details.