stephenwithav / sqlcg

Taking sqlc to the next level.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Requirements

sqlcg requires sqlc, dbmate, and Docker.

A sqlc.yaml file. Example:

version: "2"
sql:
  - engine: "mysql"
    queries: "db/queries.sql"
    schema: "db/schema.sql"
    gen:
      go:
        package: "todos"
        out: "repository/mysql/todos"
        emit_empty_slices: true

Intent

sqlc references dbmate, but doesn't demonstrate a useful workflow incorporating it.

sqlcg allows a more iterative, interactive approach.

It:

  1. Launches mysql:5.7 database.
  2. Waits for it to accept connections.
  3. Runs the database migrations.
  4. Generates the Go code via sqlc.
  5. Connects to mysql shell for testing. (Optional with >=2 arguments.)
  6. Stops docker container.

Tips

Create a sqlcg link somewhere in your path to make invoking this easier.

Future?

Postgres and SQLite database integration is likely.

Let me know in an issue if you'd like something else.

About

Taking sqlc to the next level.


Languages

Language:Shell 100.0%