|
8 | 8 |
|
9 | 9 | set -euo pipefail
|
10 | 10 |
|
11 |
| -cd "$(dirname "$0")" |
12 |
| - |
13 |
| -# The logic below depends on the exact version being correct :( |
14 |
| -go run github.com/kyleconroy/sqlc/cmd/ [email protected] generate |
15 |
| - |
16 |
| -first=true |
17 |
| -for fi in queries/*.sql.go; do |
18 |
| - # Find the last line from the imports section and add 1. |
19 |
| - cut=$(grep -n ')' "$fi" | head -n 1 | cut -d: -f1) |
20 |
| - cut=$((cut + 1)) |
21 |
| - |
22 |
| - # Copy the header from the first file only, ignoring the source comment. |
23 |
| - if $first; then |
24 |
| - head -n 6 < "$fi" | grep -v "source" > queries.sql.go |
25 |
| - first=false |
26 |
| - fi |
27 |
| - |
28 |
| - # Append the file past the imports section into queries.sql.go. |
29 |
| - tail -n "+$cut" < "$fi" >> queries.sql.go |
30 |
| -done |
31 |
| - |
32 |
| -# Move the files we want. |
33 |
| -mv queries/querier.go . |
34 |
| -mv queries/models.go . |
35 |
| - |
36 |
| -# Remove temporary go files. |
37 |
| -rm -f queries/*.go |
38 |
| - |
39 |
| -# Fix struct/interface names. |
40 |
| -gofmt -w -r 'Querier -> querier' -- *.go |
41 |
| -gofmt -w -r 'Queries -> sqlQuerier' -- *.go |
42 |
| - |
43 |
| -# Ensure correct imports exist. Modules must all be downloaded so we get correct |
44 |
| -# suggestions. |
45 |
| -go mod download |
46 |
| -goimports -w queries.sql.go |
| 11 | +SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") |
| 12 | + |
| 13 | +( |
| 14 | + cd "$SCRIPT_DIR" |
| 15 | + |
| 16 | + # The logic below depends on the exact version being correct :( |
| 17 | + go run github.com/kyleconroy/sqlc/cmd/ [email protected] generate |
| 18 | + |
| 19 | + first=true |
| 20 | + for fi in queries/*.sql.go; do |
| 21 | + # Find the last line from the imports section and add 1. |
| 22 | + cut=$(grep -n ')' "$fi" | head -n 1 | cut -d: -f1) |
| 23 | + cut=$((cut + 1)) |
| 24 | + |
| 25 | + # Copy the header from the first file only, ignoring the source comment. |
| 26 | + if $first; then |
| 27 | + head -n 6 <"$fi" | grep -v "source" >queries.sql.go |
| 28 | + first=false |
| 29 | + fi |
| 30 | + |
| 31 | + # Append the file past the imports section into queries.sql.go. |
| 32 | + tail -n "+$cut" <"$fi" >>queries.sql.go |
| 33 | + done |
| 34 | + |
| 35 | + # Move the files we want. |
| 36 | + mv queries/querier.go . |
| 37 | + mv queries/models.go . |
| 38 | + |
| 39 | + # Remove temporary go files. |
| 40 | + rm -f queries/*.go |
| 41 | + |
| 42 | + # Fix struct/interface names. |
| 43 | + gofmt -w -r 'Querier -> querier' -- *.go |
| 44 | + gofmt -w -r 'Queries -> sqlQuerier' -- *.go |
| 45 | + |
| 46 | + # Ensure correct imports exist. Modules must all be downloaded so we get correct |
| 47 | + # suggestions. |
| 48 | + go mod download |
| 49 | + goimports -w queries.sql.go |
| 50 | +) |
0 commit comments