https://github.com/olexnzarov/sqlc-pgx-migrate-template
A boilerplate template for the sqlc, pgx/v5, golang-migrate libraries
https://github.com/olexnzarov/sqlc-pgx-migrate-template
example golang-migrate pgx sqlc template
Last synced: about 2 months ago
JSON representation
A boilerplate template for the sqlc, pgx/v5, golang-migrate libraries
- Host: GitHub
- URL: https://github.com/olexnzarov/sqlc-pgx-migrate-template
- Owner: olexnzarov
- License: unlicense
- Created: 2024-05-30T12:22:34.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-05-31T21:07:39.000Z (12 months ago)
- Last Synced: 2025-01-31T17:53:16.916Z (4 months ago)
- Topics: example, golang-migrate, pgx, sqlc, template
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqlc-pgx-migrate-template
This is a boilerplate template for the following combination of libraries: [sqlc](https://github.com/sqlc-dev/sqlc), [pgx/v5](https://github.com/jackc/pgx), [golang-migrate](https://github.com/golang-migrate/migrate). This is just one of the many examples of how to use these libraries together — don't consider this as the single right way of doing things and tinker around with them yourself.**How to use this code?**
- Put your migrations into the `internal/db/migrations` directory.
- Put your queries into the `internal/db/queries` directory and add them to the `sqlc.yaml` configuration.
- Use the `db.Setup` function to run the migrations and get the pgx connection pool.## Running the example
```sh
# To start the example application
$ docker-compose up -d# To stop the example application
$ docker-compose down
``````sh
$ curl localhost:8080/authors[{"ID":"7e96f8fc-c2c6-4844-a588-9bd14b066ffc","Name":"Robert Jordan","Description":null,"AverageRating":4.225}]
```## Cleaning up the template
```sh
# To remove the example application, its Docker files, this README file, and initialize a new git repository.
# Do not forget to delete this rule after you've run it.
$ make cleanup-template# To change the module name.
$ go mod edit -module github.com/you/your-repository
```