Question:
Hello, I could not find a lot on this module called better replit db, but it was suggested to me in my last question.
It is a lot faster than the actual replit db, but it does not sync with the database when the app is restarted. I am using it for my Python Flask project called Pixel Board.
I tried running print(db)
and it shows the URL of my repl database, but it only seems to be able to add keys instead of being able to remove keys or get keys when the app is restarted or booted up.
Does anyone know how to fix this?
Repl link:
https://replit.com/@StudioHawaii/Pixel-Board?v=1
Server code:
import os
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
from betterreplitdb import db
app = Flask(__name__)
socketio = SocketIO(app)
app.config['TEMPLATES_AUTO_RELOAD'] = True #if true, it auto reloads templates if a change is made to them
app.secret_key = os.environ['SECRET_KEY'] #The secret key
board_size = 60 #The size of the pixel board (Warning: A very large size may either break the app or overload repl db)
keys = db.keys() #Gets the keys
print(keys)
print(db)
"""Routes"""
@app.route('/')
def index():
"""The index page (Board is on it)"""
return render_template('index.html', size=board_size, db=db)
"""Socketio events"""
@socketio.on('pixel_change')
def change_pixel(pixel):
db.set(pixel['Pixel'], pixel['Pixel']) #put the pixel in the database
print(db.keys())
#database.append(pixel)
emit('change_pixel', {'Pixel': pixel['Pixel'], 'Color': pixel['Color']}, broadcast=True)
socketio.run(app, host='0.0.0.0')