Skip to content

chore: split queries.sql into files by table #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
queries in one file
  • Loading branch information
coadler committed Apr 1, 2022
commit 03b80051bbe3ecae17cc4fa5702dec558ddf53ba
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)

# Generates Go code for querying the database.
coderd/database/generate: fmt/sql coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
cd coderd/database && sqlc generate && rm db_tmp.go
cd coderd/database && gofmt -w -r 'Querier -> querier' *.go
cd coderd/database && gofmt -w -r 'Queries -> sqlQuerier' *.go
coderd/database/generate.sh
.PHONY: coderd/database/generate

fmt/prettier:
Expand All @@ -32,6 +30,7 @@ endif
.PHONY: fmt/prettier

fmt/sql: $(wildcard coderd/database/queries/*.sql)
# TODO: this is slightly slow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use bash wait to make this faster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest problem is that it has to attempt to install via npx every time, otherwise it's pretty fast! Can npx be called concurrently?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhhhh. I say we require sql-formatter installed globally then.

for fi in coderd/database/queries/*.sql; do \
npx sql-formatter \
--language postgresql \
Expand Down
173 changes: 0 additions & 173 deletions coderd/database/apikeys.sql.go

This file was deleted.

67 changes: 0 additions & 67 deletions coderd/database/files.sql.go

This file was deleted.

26 changes: 26 additions & 0 deletions coderd/database/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -euo pipefail

cd "$(dirname "$0")"

sqlc generate

first=true
for fi in queries/*.sql.go; do
cut=$(grep -n ')' "$fi" | head -n 1 | cut -d: -f1)
cut=$((cut + 1))

if $first; then
head -n 4 < "$fi" | grep -v "source" > queries.sql.go
first=false
fi

tail -n "+$cut" < "$fi" >> queries.sql.go
done

rm -f queries/*.go

goimports -w queries.sql.go
gofmt -w -r 'Querier -> querier' -- *.go
gofmt -w -r 'Queries -> sqlQuerier' -- *.go
81 changes: 0 additions & 81 deletions coderd/database/organizationmembers.sql.go

This file was deleted.

Loading