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!
Release files for ShitDB 1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ShitDB-1.4.tar.gz | 5.2 kB | Details |
Release files / ShitDB-1.4.tar.gz
| Download URL | ShitDB-1.4.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef562503873c2b214aa8a67dd4f3ef46bdf593fccf09ee5748c9212807f351c2
|
|
BLAKE2b-256 checksum How to use checksums |
b7379f0100ce6296d596f229136d38cbb2691cc6549e57ee5c38f59d9614fb03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|