SQL to Objection.js Model Generator

Convert SQL CREATE TABLE statements to Objection.js ORM model classes with TypeScript types, JSON schema validation, and relation mappings.

What is SQL to Objection.js Model Generator?

This tool converts SQL CREATE TABLE statements to Objection.js ORM model classes. It generates TypeScript model definitions with proper type annotations, JSON schema validation, and relation mappings for foreign keys.

How to Use

  1. Paste your SQL CREATE TABLE statements
  2. Select your database dialect
  3. Configure type generation options
  4. Click "Generate" and copy the Objection.js models

Why Use This Tool?

Generate type-safe Objection.js model classes
Map SQL types to TypeScript types automatically
Generate JSON Schema for runtime validation
Auto-detect foreign keys and create relation mappings
Support PostgreSQL, MySQL, and SQLite dialects

Tips & Best Practices

  • Objection.js models require a static tableName property
  • Use JSON Schema for input validation before database operations
  • Foreign key references are converted to BelongsToOneRelation mappings
  • Nullable columns (without NOT NULL) get optional TypeScript types

Frequently Asked Questions

What is Objection.js?

Objection.js is a SQL-friendly ORM for Node.js built on top of Knex.js. It provides a fully-featured ORM with relations, eager loading, transactions, and JSON schema validation while staying close to SQL.

How are SQL types mapped to TypeScript types?

SQL types are mapped to TypeScript types suitable for Objection.js models. For example, INTEGER/BIGINT map to number, VARCHAR/TEXT map to string, BOOLEAN maps to boolean, TIMESTAMP/DATE map to string, JSON/JSONB map to object.

What is the jsonSchema property?

Objection.js supports JSON Schema for input validation. The jsonSchema static property defines the structure and constraints of your model data, allowing Objection.js to validate input before database operations.

How are foreign keys handled?

Foreign key references in SQL are automatically converted to Objection.js relationMappings using BelongsToOneRelation. The join configuration maps the foreign key column to the referenced table and column.

Is my SQL data sent to a server?

No, all processing happens entirely in your browser. Your SQL schema never leaves your device. The conversion is performed client-side using a regex-based parser.

Related Tools