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
- Paste your SQL CREATE TABLE statements
- Select your database dialect
- Configure type generation options
- Click "Generate" and copy the TypeScript types
Why Use This Tool?
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.