Giter Site home page Giter Site logo

sputnik's Introduction

sputnik

This repo demonstrates how to setup a Rust micro-service using Rocket, async-graphql, and sqlx. For some background on this, go here.

Note: This repo assumes you have some familiarity with Rust, graphQL, and SQL.

Installation Steps

Cloning related repo

Besides cloning this repo, you will also need to clone async-graphql. The reason you need to do that is because the Rocket support for async-graphql is currently unpublished. Make the necessary changes to Cargo.toml to update the path information to async-graphql and async-graphql-rocket.

Database Setup

  1. This project assumes that you have postgres installed locally. At this point, you will need to create a starwars database.

    psql -h localhost -U postgres -w -c "create database starwars;"

  2. Create a .env file in the project root directory and add the following line:

    DATABASE_URL="postgres://postgres:<YOUR_PWD>@localhost:5432/starwars"

    This environment variable is used as a configuration input to the database connection pool to indicate where to find the database

Seeding your database with migrations

Migration tables have been created to seed the `starwars` schema in your database.
  1. To use the migration scripts, install the golang-migrate CLI.

    Go here and follow instructions to install the CLI.

  2. After installation, set this up for golang-migrate:

    export POSTGRESQL_URL='postgres://postgres:<YOUR_PWD>@localhost:5432/starwars?sslmode=disable'

  3. When you are ready to run the migration, run this from the project's root directory:

    migrate -source file://./src/db/migrations -database postgres://postgres:<YOUR_PWD>@localhost:5432/starwars?sslmode=disable up

    Note: If you run into migration quirks, read the documentation at golang-migrate

Running the service

The current configuration in Rocket.toml has been setup to run the micro-service on port 7600. After you have cargo build and cargo run, you can browse the graphQL server playground here:

http://localhost:7600/

Extending the database

This section can be skipped if you are not interested in extending the database.
  1. If you want to extend the tables, you can create new migration scripts,

migrate create -ext sql -dir src/db/migrations -seq <MIGRATION_FILE_NAME>

  1. If you want to update the scripts only, you will have to do a down, followed by an up

    migrate -source file://./src/db/migrations -database postgres://postgres:<YOUR_PWD>@localhost:5432/starwars?sslmode=disable down

    migrate -source file://./src/db/migrations -database postgres://postgres:<YOUR_PWD>@localhost:5432/starwars?sslmode=disable up

    Note: If you encounter errors in your scripts, you will need to truncate the scheme_migrations table, and drop the starwars schema.

sputnik's People

Contributors

lionkeng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.