-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store humans in an actual database
This uses `sqlx` to read/write humans from/to the sample-db. The schema consists of a custom enum type for episodes, and a table for humans. For now, the same structs as were used for the GraphQL schema are being used to (de)serialize database values. This would have been quite smooth, but sadly, `sqlx`'s derivation can't handle `Vec`s of custom enums (launchbadge/sqlx#298), so we have to jump through some hoops by introducing `EpisodeSlice` and `EpisodeVec` newtypes, which can then implement the required traits (plus all the required juniper traits, which is the bigger pain). Since we're using `sqlx`'s macros to check queries at compile time, we need to connect to the database during compilation. The macro will use the `DATABASE_URL` environment variable, which it can read from a `.env` file, so we now write one of these files as part of `make prepare-db` (note that this is for the benefit of editors, language servers, etc., `make run` would already inherit the `DATABASE_URL` when compiling).
- Loading branch information
Chris Connelly
committed
Dec 11, 2021
1 parent
847575c
commit b1db5bf
Showing
10 changed files
with
214 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.env | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
CREATE TYPE episode AS ENUM ('new_hope', 'empire', 'jedi'); | ||
|
||
CREATE TABLE humans ( | ||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
name TEXT NOT NULL UNIQUE, | ||
appears_in episode[] NOT NULL, | ||
home_planet TEXT NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.