https://github.com/doutivity/research-sqlc-go
Effective work with SQL in Go
https://github.com/doutivity/research-sqlc-go
sqlc
Last synced: about 1 month ago
JSON representation
Effective work with SQL in Go
- Host: GitHub
- URL: https://github.com/doutivity/research-sqlc-go
- Owner: doutivity
- License: mit
- Created: 2023-09-22T22:44:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-08T20:12:20.000Z (over 2 years ago)
- Last Synced: 2024-06-21T19:53:15.752Z (over 1 year ago)
- Topics: sqlc
- Language: Go
- Homepage: https://dou.ua/forums/topic/34806/
- Size: 12.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Effective work with SQL in Go
- [Go: ефективна робота з SQL](https://dou.ua/forums/topic/34806/)
### Support Ukraine 🇺🇦
- Help Ukraine via [SaveLife fund](https://savelife.in.ua/en/donate-en/)
- Help Ukraine via [Dignitas fund](https://dignitas.fund/donate/)
- Help Ukraine via [National Bank of Ukraine](https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zboru-koshtiv-na-potrebi-armiyi)
- More info on [war.ukraine.ua](https://war.ukraine.ua/) and [MFA of Ukraine](https://twitter.com/MFA_Ukraine)
### Testing
```bash
make env-up
make docker-go-version
make docker-pg-version
make migrate-up
make go-test
make env-down
```
```bash
make env-up
time make test
```
```text
real 0m16.016s
user 0m0.168s
sys 0m0.079s
```
### Examples
```yaml
version: "2"
sql:
- engine: "postgresql"
queries: "./internal/storage/postgres/queries/"
schema: "./internal/storage/postgres/migrations/"
gen:
go:
package: "dbs"
sql_package: "database/sql"
out: "./internal/storage/postgres/dbs"
emit_prepared_queries: true
```
```sql
-- name: CompanyNewAndGetID :one
INSERT INTO companies (alias, name, created_by, created_at)
VALUES (@alias, @name, @created_by, @created_at)
RETURNING id;
```
### Development
```bash
make create-new-migration-file NAME=migration_name
```
```bash
mkdir -p ./internal/storage/postgres/queries/
```
```bash
make generate-sqlc
```
### Tools
* [github.com/sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc)
* [github.com/pressly/goose](https://github.com/pressly/goose)