Skip to content

Commit 1b86b33

Browse files
author
Chris Connelly
committed
chore: add sqlx scaffolding
This adds installation of `sqlx-cli` to the README, which is now used in `make prepare-db` to create and migrate the database. `make run` now depends on `prepare-db`, so the project can still be launched with that single command. The database isn't used yet.
1 parent 9401352 commit 1b86b33

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
@PHONY: start-db stop-db run
1+
@PHONY: prepare-db start-db stop-db run
2+
3+
export PGHOST ?= localhost
4+
export PGPORT ?= 5432
5+
export PGUSER ?= postgres
6+
export PGPASSWORD ?= password
7+
export PGDATABASE ?= sample
8+
export DATABASE_URL ?= postgres://$(PGUSER):$(PGPASSWORD)@$(PGHOST):$(PGPORT)/$(PGDATABASE)
9+
10+
prepare-db: start-db
11+
@sqlx database create
12+
@sqlx migrate run
213

314
start-db:
415
@scripts/start-db.sh
516

617
stop-db:
718
@scripts/stop-db.sh
819

9-
run: start-db
20+
run: start-db prepare-db
1021
@RUST_LOG=rust_graphql_sample=debug,tower_http=debug cargo run

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ A sample of GraphQL in Rust.
55
## Setup
66

77
1. [Get Rust](https://rustup.rs/).
8-
2. `git clone https://github.com/connec/rust-graphql-sample`
9-
3. `make run`
8+
2. Install [`sqlx-cli`](https://github.com/launchbadge/sqlx/blob/master/sqlx-cli/README.md)
9+
```sh
10+
cargo install sqlx-cli --no-default-features --features postgres
11+
```
12+
3. `git clone https://github.com/connec/rust-graphql-sample`
13+
4. `make run` – this will start a PostgreSQL container, prepare a sample database, and start the server.
1014

1115
[GraphiQL](https://github.com/graphql/graphiql) is served from http://localhost:3000/, and the GraphQL API itself from http://localhost:3000/query.
12-
The `make` task is just setting a sensible default log filter and calling `cargo run`.

migrations/.gitkeep

Whitespace-only changes.

scripts/start-db.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ set -euo pipefail
55
container_name=sample-db
66
container_image=postgres:14
77

8-
export PGHOST=localhost
9-
export PGPORT=5432
10-
export PGUSER=postgres
11-
export PGPASSWORD=password
12-
138
if ! [[ "$(docker ps --filter name="$container_name" --latest -q)" != '' ]]; then
149
if
1510
! output="$(

0 commit comments

Comments
 (0)