SQL to Sequelize Model

Convert SQL CREATE TABLE statements to Sequelize model definitions with DataTypes mapping, associations, and indexes.

About This Tool

The SQL to Sequelize converter is a free browser-based tool that transforms SQL CREATE TABLE statements into Sequelize model definitions. Sequelize is the most popular Node.js ORM, supporting PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server. Instead of manually writing Model.init() calls and mapping every column type to a DataTypes constant, this tool automates the entire process and generates clean, production-ready Sequelize models in seconds.

The converter parses your SQL and maps column types to their Sequelize DataTypes equivalents. Standard SQL types like VARCHAR, INTEGER, BOOLEAN, TIMESTAMP, and JSON are all handled automatically. It recognizes database-specific types such as PostgreSQL's SERIAL and JSONB, MySQL's AUTO_INCREMENT and TINYINT(1) boolean pattern, and maps them to the correct Sequelize constants including DataTypes.UUID, DataTypes.JSONB, DataTypes.DATEONLY, and more.

Relationships are inferred from FOREIGN KEY constraints and inline REFERENCES clauses. The tool generates belongsTo associations with the correct foreignKey and targetKey options, and provides commented hasMany reverse association hints so you can wire up both sides of a relationship. Composite primary keys, composite unique constraints, and CREATE INDEX statements are all converted to Sequelize's indexes option on the model.

You can toggle between TypeScript and JavaScript output. TypeScript mode generates full type-safe code including Attributes and CreationAttributes interfaces, extending Model<> generics, and properly typed class properties. JavaScript mode produces CommonJS require syntax ready to drop into any Express.js or Node.js project.

All processing happens entirely in your browser. Your SQL statements never leave your machine — there are no server round-trips, no logging, and no third-party services involved. This makes it safe to use with production database schemas. The tool is ideal for migrating legacy SQL databases to Sequelize, bootstrapping new projects, or learning how SQL structures translate to Sequelize's model API. If you are working with other ORMs, try our SQL to Prisma converter for Prisma schema generation.

How to Use

  1. Paste one or more SQL CREATE TABLE statements into the SQL Input panel on the left.
  2. The Sequelize model output updates automatically in the right panel as you type.
  3. Toggle between TypeScript and JavaScript to choose your preferred output format.
  4. TypeScript mode generates typed Model class definitions with Attributes and CreationAttributes interfaces.
  5. JavaScript mode generates CommonJS-style code with require and module.exports.
  6. Click Copy or press Ctrl+Shift+C to copy the generated Sequelize code to your clipboard.
  7. Use Sample to load example SQL with multiple tables and foreign key relationships.

Popular SQL to Sequelize Examples

View all SQL to Sequelize examples →

FAQ

Which SQL dialects does the converter support?

The parser supports standard SQL CREATE TABLE syntax and handles dialect-specific features from PostgreSQL, MySQL, SQLite, and SQL Server. This includes SERIAL / BIGSERIAL (PostgreSQL), AUTO_INCREMENT (MySQL), AUTOINCREMENT (SQLite), and IDENTITY (SQL Server). The generated Sequelize code works with any database supported by Sequelize.

How are SQL types mapped to Sequelize DataTypes?

Common mappings include: VARCHAR to DataTypes.STRING, INT/INTEGER to DataTypes.INTEGER, BIGINT to DataTypes.BIGINT, BOOLEAN to DataTypes.BOOLEAN, DECIMAL/NUMERIC to DataTypes.DECIMAL, TIMESTAMP/DATETIME to DataTypes.DATE, DATE to DataTypes.DATEONLY, JSON to DataTypes.JSON, JSONB to DataTypes.JSONB, TEXT to DataTypes.TEXT, UUID to DataTypes.UUID, and BLOB/BYTEA to DataTypes.BLOB. Length parameters like VARCHAR(255) are preserved as DataTypes.STRING(255).

How are foreign keys converted to Sequelize associations?

Both inline REFERENCES clauses and table-level FOREIGN KEY constraints are detected. The tool generates belongsTo associations with foreignKey and targetKey options. It also provides commented hasMany reverse association hints so you can easily wire up both sides of the relationship in your application code.

What is the difference between TypeScript and JavaScript output?

TypeScript output includes full type definitions: an Attributes interface for all columns, a CreationAttributes type for optional fields (auto-increment, nullable, defaults), a class extending Model<Attributes, CreationAttributes> with typed properties, and a static associate() method. JavaScript output uses CommonJS require/module.exports syntax without type annotations.

Does it handle composite primary keys and indexes?

Yes. Composite primary keys defined via PRIMARY KEY (col1, col2) are converted to an entry in Sequelize's indexes option with unique: true. Composite unique constraints become unique index entries, and CREATE INDEX statements become regular index entries. All columns in a composite primary key are marked as allowNull: false.

Is my data safe?

Yes. All parsing and code generation runs entirely in your browser using JavaScript. No data is sent to any server. You can verify this by checking the Network tab in your browser's developer tools while using the tool.

Can I convert multiple tables at once?

Yes. Paste multiple CREATE TABLE statements separated by semicolons and the tool will generate a Sequelize model for each table. Foreign key relationships between tables are automatically detected and converted to association declarations.

Related Tools