What is SQL to sqlc Generator?
This tool converts SQL CREATE TABLE statements and annotated query statements into sqlc Go code. sqlc is a Go code generator that compiles SQL into type-safe Go code, generating model structs, query functions, and a Querier interface. Unlike ORMs, sqlc lets you write plain SQL and generates fully typed Go code.
How to Use
- Set the package name (default: "db") and select your database engine
- Toggle options: JSON tags and prepared queries
- Paste your SQL CREATE TABLE statements and annotated queries into the input area
- Use sqlc annotations: -- name: FunctionName :one/:many/:exec/:execrows
- Click "Generate sqlc Code" to create sqlc.yaml, schema.sql, and query.sql.go
- Copy each output file and save them in your Go project
Why Use This Tool?
Tips & Best Practices
- Use -- name: GetAuthor :one for queries returning a single row
- Use -- name: ListAuthors :many for queries returning multiple rows
- Use -- name: DeleteAuthor :exec for queries with no return value
- Use -- name: UpdateCount :execrows for queries returning affected row count
- The tool infers parameter names and types from the SQL context (INSERT columns, WHERE clauses)
Frequently Asked Questions
What is sqlc?
sqlc is a Go code generator that compiles SQL queries into type-safe Go code. Unlike ORMs, sqlc lets you write plain SQL and generates Go structs and functions with proper type checking, eliminating runtime SQL errors. It supports PostgreSQL, MySQL, and SQLite.
How do sqlc query annotations work?
sqlc uses SQL comments to annotate queries. For example, `-- name: GetAuthor :one` defines a query named GetAuthor that returns a single row. `:many` returns multiple rows, `:exec` executes without returning rows, and `:execrows` returns the number of affected rows.
Which database engines are supported?
This tool supports PostgreSQL, MySQL, and SQLite engines. The generated sqlc.yaml configuration and Go type mappings are adjusted based on the selected engine.
Is my SQL data sent to a server?
No, all processing happens entirely in your browser. Your SQL schema and queries never leave your device. The conversion is performed client-side using a regex-based parser.