Skip to main content
Version: 0.4.x 🚧

Running the example

The project codebase comes with an example database, you can use to run the example project.

In this article we will follow the instructions on how to setup the example project, and we can perform some useful queries.

Requirements

  1. rustup: https://rustup.rs/
  2. mysql / postgres database (optional)

Install from Cargo

cargo install seaography-cli

Install from source

  1. Clone project

    git clone git@github.com:SeaQL/seaography.git
  2. Build project

    cd ./seaography/cli
    cargo install --path .

MySQL

  1. Locate project

    cd ./examples/mysql
  2. Create database

    mysql -uroot -p -h 127.0.0.1 mysql -e 'CREATE DATABASE `sakila`'
  3. Import schema

    mysql -uroot -p -h 127.0.0.1 sakila < sakila-schema.sql
  4. Import data

    mysql -uroot -p -h 127.0.0.1 sakila < sakila-data.sql

Postgres

  1. Locate project

    cd ./examples/postgres
  2. Create database

    psql -q postgres://postgres:postgres@localhost/postgres -c 'CREATE DATABASE "sakila"'
  3. Import schema

    psql -q postgres://postgres:postgres@localhost/sakila < sakila-schema.sql
  4. Import data

    psql -q postgres://postgres:postgres@localhost/sakila < sakila-data.sql

SQLite

  1. Locate project
    cd ./examples/sqlite

Extending and configuring code

You are free to modify the code and change things to fit your needs. For more info How to extend generated code.

Running server

cargo run

http://127.0.0.1:8000/

Regenerating code

Here are the instructions on how we can generate the examples from scratch.

  1. Set working directory to Seaography folder

    $ cd ./seaography
  2. Build project

    cargo build
  3. Clean generated code

    rm -rf ./examples/{mysql|sqlite|postgres}/src
  4. Generate code

    cd ./examples/{mysql|sqlite|postgres}
    seaography-cli <database_url> seaography-example .

    * Example database urls "sqlite://sakila.db", "mysql://username:password@127.0.0.1/sakila"

Query examples

Fetch films and their actors

{
film(
pagination: { page: { limit: 1, page: 1 } }
filters: { releaseYear: { eq: 2006 } }
orderBy: { title: ASC }
) {
nodes {
title
description
releaseYear
actor {
nodes {
firstName
lastName
}
}
}
}
}

Response

{
"data": {
"film": {
"nodes": [
{
"title": "ACE GOLDFINGER",
"description": "A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China",
"releaseYear": 2006,
"actor": {
"nodes": [
{
"firstName": "BOB",
"lastName": "FAWCETT"
},
{
"firstName": "MINNIE",
"lastName": "ZELLWEGER"
},
{
"firstName": "SEAN",
"lastName": "GUINESS"
},
{
"firstName": "CHRIS",
"lastName": "DEPP"
}
]
}
}
]
}
}
}

Fetch store and its staff

{
store(filters: { storeId: { eq: 1 } }) {
nodes {
storeId
address {
address
address2
}
staff {
firstName
lastName
}
}
}
}

Response

{
"data": {
"store": {
"nodes": [
{
"storeId": 1,
"address": {
"address": "47 MySakila Drive",
"address2": null
},
"staff": {
"firstName": "Mike",
"lastName": "Hillyer"
}
}
]
}
}
}

Fetch inactive customers with pagination

{
customer(
filters: { active: { eq: 0 } }
pagination: { page: { page: 2, limit: 3 } }
) {
nodes {
customerId
lastName
email
}
paginationInfo {
pages
current
}
}
}

Response

{
"data": {
"customer": {
"nodes": [
{
"customerId": 315,
"lastName": "GOODEN",
"email": "KENNETH.GOODEN@sakilacustomer.org"
},
{
"customerId": 368,
"lastName": "ARCE",
"email": "HARRY.ARCE@sakilacustomer.org"
},
{
"customerId": 406,
"lastName": "RUNYON",
"email": "NATHAN.RUNYON@sakilacustomer.org"
}
],
"paginationInfo": {
"pages": 5,
"current": 2
}
}
}
}

The query above using cursor pagination

{
customer(
filters: { active: { eq: 0 } }
pagination: { cursor: { limit: 3, cursor: "Int[3]:271" } }
) {
nodes {
customerId
lastName
email
}
pageInfo {
hasPreviousPage
hasNextPage
endCursor
}
}
}

Response

{
"data": {
"customer": {
"nodes": [
{
"customerId": 315,
"lastName": "GOODEN",
"email": "KENNETH.GOODEN@sakilacustomer.org"
},
{
"customerId": 368,
"lastName": "ARCE",
"email": "HARRY.ARCE@sakilacustomer.org"
},
{
"customerId": 406,
"lastName": "RUNYON",
"email": "NATHAN.RUNYON@sakilacustomer.org"
}
],
"pageInfo": {
"hasPreviousPage": true,
"hasNextPage": true,
"endCursor": "Int[3]:406"
}
}
}
}