SQLGen is a command-line tool written in Go that helps you generate SQL queries efficiently.
- Generate basic SQL queries for PostgreSQL and MySQL
To install SQLGen, you need to have Go installed on your machine. Then, you can use the following command to install SQLGen:
# postgres
go install github.com/miyataka/sqlgen/cmd/psqlgen@latest
# mysql
go install github.com/miyataka/sqlgen/cmd/mysqlgen@latestAfter installing SQLGen, you can use it from the command line. Here are some examples of how to use SQLGen:
# Generate SQL queries for PostgreSQL
psqlgen --dsn="postgres://user:password@localhost:5432/dbname"
# Generate SQL queries for MySQL
mysqlgen --dsn= "user:password@tcp(localhost:3306)/dbname"When using with sqlc, you can generate comment for sqlc with just --sqlc flag:
# Generate SQL queries for PostgreSQL with comments for sqlc
psqlgen --dsn="postgres://user:password@localhost:5432/dbname" --sqlc
# Generate SQL queries for MySQL with comments for sqlc
mysqlgen --dsn= "user:password@tcp(localhost:3306)/dbname" --sqlcYou can skip specific tables from SQL generation using the --skip-tables flag:
# Skip a single table
psqlgen --dsn="postgres://user:password@localhost:5432/dbname" --skip-tables=migrations
# Skip multiple tables (comma-separated)
psqlgen --dsn="postgres://user:password@localhost:5432/dbname" --skip-tables=migrations,logs,temp_data
# MySQL example with skip tables
mysqlgen --dsn="user:password@tcp(localhost:3306)/dbname" --skip-tables=migrations,logs
# Combine with sqlc flag
psqlgen --dsn="postgres://user:password@localhost:5432/dbname" --sqlc --skip-tables=migrations,logsWe welcome contributions to SQLGen! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License.