Quick Start with GitHub

This guide takes you through using a GitHub repository as a database.

📘

Usage of "Github as storage" is experimental

We don't recommend using Github as a storage backend for production workloads. However, it's used throughout the docs because of developer familiarity and observability of the database.

Prerequisites

You need two things to store data in GitHub via Cloud State.

  1. A private or a public GitHub repo
  2. A personal access token with read/write access to the contents of that repo.
    1. Use this page to provision a token

Generate an origin token

Make sure to replace , and in the example curl below.

🚧

The command below assumes you have jq installed.

REPO="your/repo" # Replace this  
GITHUB_TOKEN="your-token" # Replace this  
YOUR_EMAIL="[email protected]" # Replace this

C9_TOKEN=$(curl -XPOST https://c9db.io/tokens  
    -H "Content-Type: application/json"  
    -d '{  
        "type":"github",  
        "repo":"'"$REPO"'",  
        "token":"'"$GITHUB_TOKEN"'",  
        "email": "'"$YOUR_EMAIL"'"  
    }' | jq -r .token)

This will store your token in an environment variable called C9_TOKEN.

Store data

Storing data is as easy as issuing a PUT call with the C9_TOKEN.

curl -XPUT https://c9db.io/values/foo
  -H "Authorization: Bearer $C9_TOKEN"  
  -H "Content-Type: text/plain"  
  -d "bar"

This will evenually create a file in your $REPO named foo, with the content bar. However, this might take up to minute to be replicated.

Until it is replicated, Cloud State server will serve the value from its cache.

Read data

To read the data you just stored, we can issue a GET call with the C9_TOKEN.

curl https://c9db.io/values/foo
	-H "Authorization: Bearer $C9_TOKEN"

This will return the value you stored earlier.