Skip to content

KanchiShimono/rust-rocket-juniper-graphql-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-rocket-juniper-graphql-example

Rust GraphQL server example. This example uses crates juniper, rocket and diesel.

Setup database

Before running example, you have to create database and user.

CREATE USER IF NOT EXISTS maxroach;
CREATE DATABASE IF NOT EXISTS review;
GRANT ALL ON DATABASE review TO maxroach;

Or use scripts in bin directory.

./bin/create_db.sh

Migration

After creating database and user, you can migrate tables by diesel cli. Following command generate migration directory and up/down.sql.

diesel setup

Then you have to fix up/down.sql under the migrations/00000000000000_diesel_initial_setup. Bacause sql files generated by diesel setup set custom functions to database, but cockroachdb does not support function yet.

-- up.sql
CREATE TABLE person (
    id UUID NOT NULL,
    name VARCHAR NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE post (
    id UUID NOT NULL,
    person_id UUID NOT NULL,
    text VARCHAR NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (person_id)
    REFERENCES person (id)
);


-- down.sql
DROP TABLE IF EXISTS post;
DROP TABLE IF EXISTS person;

Run migration.

diesel migration run

diesel migration run command generates diesel table schema file src/db/schemas.rs.

Releases

No releases published

Packages

No packages published