Skip to main content

A json database to fix the persistence problem on Heroku using Github!!

Project description

ShitDB

A json database to fix the persistence problem on Heroku using GitHub!!


The problem:

In Heroku's free dev plan, files are not saved for more than 24 hours (or so). So, a json file will reset, the way it was uploaded, vanishing all the stored data. Read more here.

Solution:

Using ShitDB and your GitHub account, this problem can be fixed!! But, there are other databases too. Using free add-ons like PostgreSQL or using MongoDB Atlas, is a way too, and is of-course free. Using JSON storage is quite easy. For beginners, setting up MongoDB or Heroku Postgres addon can be quite a tricky task. This is an easier way!!

How?

As your json file gets updated, it is simultaneously uploaded to a specified repository in your account. On restart of your Heroku Dynos, the data from the json file will be retrieved from your GitHub and saved to the local json file.

Requirements:

  • Your GitHub Token. how?
  • A repo as a database. Can be Private or Public!
  • Your email and username associated with your GitHub account.
  • Of-course a Heroku app. how?
  • Uhh...nothing else I guess

CODE ARENA

$ pip install ShitDB
"""
A MINIMAL USAGE OF ShitDB!
"""

import json
import ShitDB


TOKEN = "ghp_github_token_999xyz"
AUTHOR = ("username","email")
REPO = "Repo-As-Database"


db = ShitDB.DB(github_token=TOKEN,database_repo=REPO,author=AUTHOR) # optional => branch="my-branch"


## YOUR STUFF

def register_user(user,id):
    with open("users.json","r") as f:
		old = json.load(f)
	old.update({user:id}) # old became new!
	
	db.push_remote_data(content=old,file_path="my_files/users.json") # file path on github
	

def get_user_data(user):
	data = db.load_remote_data("my_files/users.json",eval_output=True) # By-Default the return type is <str> | eval_output=True to convert <str> to <dict>
	id = data[user]
	return id
	

THIS WAS MADE BY ME FOR MY DISCORD BOT. DO INVITE IT!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ShitDB-1.4.tar.gz (5.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page