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 details)

Uploaded Source

File details

Details for the file ShitDB-1.4.tar.gz.

File metadata

  • Download URL: ShitDB-1.4.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for ShitDB-1.4.tar.gz
Algorithm Hash digest
SHA256 ef562503873c2b214aa8a67dd4f3ef46bdf593fccf09ee5748c9212807f351c2
MD5 ec32ccd0203553b4a486b38cf4a46656
BLAKE2b-256 b7379f0100ce6296d596f229136d38cbb2691cc6549e57ee5c38f59d9614fb03

See more details on using hashes here.

Supported by

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