SQL to Kysely Type Generator

Convert SQL CREATE TABLE statements to Kysely type definitions for TypeScript. Generate Database interfaces with proper type mapping for PostgreSQL, MySQL, and SQLite.

What is SQL to Kysely Type Generator?

This tool converts SQL CREATE TABLE statements to Kysely type definitions for TypeScript. It maps SQL column types to TypeScript types, handles nullable columns, and generates the Database interface with all table definitions.

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 TypeScript types

Why Use This Tool?

Generate type-safe Kysely Database interfaces
Map SQL types to TypeScript types automatically
Handle nullable columns with union types
Support PostgreSQL, MySQL, and SQLite dialects
Generate Generated<> types for auto-increment columns

Tips & Best Practices

  • Kysely requires a Database interface for type-safe queries
  • Use Generated<> for columns with DEFAULT or SERIAL
  • Nullable columns (without NOT NULL) get | null type
  • The Database interface maps table names to table types

Frequently Asked Questions

What is Kysely?

Kysely is a type-safe SQL query builder for TypeScript. It provides full type inference for your database schema through a Database interface, allowing you to write SQL queries with compile-time type checking and autocompletion.

What does Generated<> do?

The Generated<> type in Kysely marks columns whose values are automatically generated by the database, such as SERIAL/auto-increment columns or columns with DEFAULT values. It makes the column optional in insert operations while keeping it non-nullable in select results.

How are SQL types mapped to TypeScript types?

SQL types are mapped based on the dialect. For example, SERIAL/BIGSERIAL map to Generated<number>, INTEGER/BIGINT map to number, VARCHAR/TEXT map to string, BOOLEAN maps to boolean, TIMESTAMP/DATE map to Date, JSON/JSONB map to unknown, and BYTEA/BLOB map to Buffer.

What are Insertable and Updatable helpers?

Insertable<T> and Updatable<T> are Kysely utility types that derive the shape of data for INSERT and UPDATE operations. Insertable makes Generated columns optional, while Updatable makes all columns optional since you typically only update some fields.

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