Skip to content

Menu

SQL to Sequelize

Convert SQL to Sequelize models

Runs entirely in your browserDatabaseFree, no sign-up
Loading tool

01What is SQL to Sequelize?

You have a database that already exists and an Express app that now wants Sequelize. Retyping every column into DataTypes is slow and easy to get wrong. Paste one CREATE TABLE statement and this tool writes a Model subclass with a static initModel(sequelize) method that calls init() with your columns. The parser is more careful than a quick split on commas. It strips SQL comments, finds the column list by matching its closing parenthesis, and ignores trailing options like ENGINE=InnoDB. It then splits on top-level commas outside quotes, so DECIMAL(10, 2) and a default like 'a, b' survive intact. Schema-qualified names such as public.accounts and IF NOT EXISTS are accepted. Types are mapped to the DataTypes listed in the Sequelize docs. INT becomes INTEGER, and BIGINT, SMALLINT, TINYINT, FLOAT and DOUBLE map to their namesakes. DECIMAL and NUMERIC keep precision and scale. VARCHAR and CHAR become STRING(length), and DATE becomes DATEONLY. DATETIME, TIMESTAMP and TIMESTAMPTZ become DATE. JSON, JSONB, UUID, BOOLEAN, BLOB and ENUM('a','b') are covered too. PostgreSQL SERIAL and BIGSERIAL turn into INTEGER or BIGINT with autoIncrement: true. Column options come along as well. PRIMARY KEY, AUTO_INCREMENT, UNIQUE and NOT NULL (as allowNull: false) are copied over. Defaults are handled with some thought. Quoted strings become escaped JavaScript strings and numbers stay numbers. CURRENT_TIMESTAMP and NOW() become DataTypes.NOW, gen_random_uuid() becomes DataTypes.UUIDV4, and other database expressions are wrapped in sequelize.literal(). Inline REFERENCES and table-level FOREIGN KEY clauses become references entries. INDEX, KEY and UNIQUE lines go into the indexes option. A quick example. CREATE TABLE posts (id INT PRIMARY KEY, slug VARCHAR(80), INDEX idx_slug (slug)) gives id as DataTypes.INTEGER with primaryKey: true, slug as DataTypes.STRING(80) with allowNull: true, and indexes: [{ name: "idx_slug", fields: ["slug"] }]. Pick TypeScript for an ES import and export class, or JavaScript for require and module.exports. Both set tableName and timestamps: false, so Sequelize won't go looking for createdAt and updatedAt columns you don't have. There are limits. It reads one CREATE TABLE at a time. It does not write associations like hasMany or belongsTo. Types it doesn't know, such as INET or geometry types, quietly fall back to DataTypes.STRING. The class name is just the capitalised table name, so users becomes Users. Parsing happens in the page, and the schema you paste is not uploaded.

Node.js developers introducing Sequelize to an app whose MySQL or PostgreSQL schema already exists as SQL. The tool runs entirely in your browser, so your data never leaves your device.

02How to use SQL to Sequelize

  1. Paste one statement into the SQL CREATE TABLE box, or load an example.
  2. Pick TypeScript or JavaScript next to Output.
  3. Click Convert. If the statement can't be parsed, an error message appears below the buttons.
  4. Read the generated model, then click Copy, or Reset to clear everything.

03Worked examples

Input: CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, balance DECIMAL(10,2) DEFAULT 0, created_at TIMESTAMP );
Result: export class Users extends Model { static initModel(sequelize: Sequelize) { Users.init( { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, email: { type: DataTypes.STRING(255), allowNull: false, unique: true }, balance: { type: DataTypes.DECIMAL(10, 2), allowNull: true, defaultValue: 0 }, created_at: { type: DataTypes.DATE, allowNull: true }, }, { sequelize, tableName: "users", timestamps: false } …
TypeScript output, condensed: the tool puts each property on its own line. TIMESTAMP maps to DataTypes.DATE.
Input: CREATE TABLE tags (id SERIAL PRIMARY KEY, name TEXT NOT NULL, is_active BOOLEAN DEFAULT true); with JavaScript selected
Result: const { Model, DataTypes } = require("sequelize"); class Tags extends Model { static initModel(sequelize) { Tags.init( { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, name: { type: DataTypes.TEXT, allowNull: false }, is_active: { type: DataTypes.BOOLEAN, allowNull: true, defaultValue: true }, … module.exports = Tags;
Condensed. SERIAL becomes INTEGER with autoIncrement: true, and JavaScript output uses require and module.exports.
Input: CREATE TABLE orders (id BIGSERIAL PRIMARY KEY, user_id INT NOT NULL REFERENCES users(id), status ENUM('new','paid') DEFAULT 'new');
Result: user_id: { type: DataTypes.INTEGER, allowNull: false, references: { model: "users", key: "id" } }, status: { type: DataTypes.ENUM("new", "paid"), allowNull: true, defaultValue: "new" },
Only the user_id and status attributes shown, condensed. id becomes BIGINT with autoIncrement.
Input: CREATE TABLE events (id UUID PRIMARY KEY DEFAULT gen_random_uuid(), payload JSONB, at TIMESTAMPTZ DEFAULT now(), ip INET);
Result: id: { type: DataTypes.UUID, primaryKey: true, defaultValue: DataTypes.UUIDV4 }, payload: { type: DataTypes.JSONB, allowNull: true }, at: { type: DataTypes.DATE, allowNull: true, defaultValue: DataTypes.NOW }, ip: { type: DataTypes.STRING, allowNull: true },
Attributes only, condensed. INET is unknown, so it falls back to DataTypes.STRING.
Input: CREATE TABLE posts (id INT PRIMARY KEY, slug VARCHAR(80), INDEX idx_slug (slug));
Result: { sequelize, tableName: "posts", timestamps: false, indexes: [ { name: "idx_slug", fields: ["slug"] }, ], }
Only the options object shown. The INDEX line becomes a named entry in indexes.

04Common use cases

  • Adding Sequelize to an Express app that sits on an existing MySQL or PostgreSQL database
  • Turning tables from a mysqldump --no-data or pg_dump -s schema dump into model files one by one
  • Checking which DataTypes value matches a column like TIMESTAMPTZ, JSONB or DECIMAL(10,2)
  • Getting foreign keys and named indexes into the model so sync() in tests builds the same structure
  • Producing a JavaScript model for an older CommonJS codebase and a TypeScript one for a newer service from the same DDL

05Tips

  • Switching between TypeScript and JavaScript regenerates the current result, so you don't have to click Convert again.
  • Scan the output for DataTypes.STRING on columns that were not text. That is the fallback for unknown types like INET.
  • references only describes the foreign key. Add belongsTo and hasMany yourself if you want include queries to work.
  • If your tables have created_at and updated_at, flip timestamps to true and set createdAt: 'created_at' and updatedAt: 'updated_at'.
  • Rename the class to the singular form (User instead of Users) if that's the convention in the rest of your code.

06Related concepts

Sequelize, ORM, DataTypes, Database migrations, DDL.

Frequently Asked Questions

What is SQL to Sequelize?

SQL to Sequelize is a free, browser-based developer tool on AIDToolStack. Convert SQL to Sequelize models It requires no installation or sign-up and works entirely in your browser.

Is SQL to Sequelize free to use?

Yes. No sign-up, no fees and no usage cap.

Does SQL to Sequelize store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe