Access data from database

Hello! I have a project that I want to start. It is a capital simulation. Theoretically, you would create an account to log into or whatever, and it would have account data save in the database. That’s all good I know how to do that, but the only problem is that when I use an SQLite database, it doesn’t save, it will revert back to what it was before it ran if you are not the owner. The replit DB doesn’t work either because I can’t access the data from another account if they are not an admin (the replit DB is specific to the user, no one else can access it.) I assume every other database is like SQLite as they are just any other files that wont save. Do you have any suggestions? Thanks!

P.S. this is planned to be in python

The problem is that databases arent copied when other users run it, as they make a copy of the code and run it. This helps secure your database from attackers trying to spam it with data or steal its contents. However, you can add authentication to your database proxy by using CLI Auth (Repl Identity but fixed and with DB access control) which I will be releasing in a few days.

2 Likes

Yes, that was my plan already. I just need to know how to make the database in one spot. (I already know how to encrypt and stuff with a secret key)

Consider using a database proxy which allows you to share the database API with other clients.

1 Like

@python660 How do I go about this? are you saying an external database? please elaborate lol

make a fork of https://replit.com/@util/Replit-Database-proxy#main.py then use the following code in your client:

from replit import db
db.db_url = "https://repl-name.yourusername.repl.co"
db["foo"] = "bar"

@python660 is this out of date? Its giving me an error.

you need to put in the link to your database proxy.

e.g. replitdatabaseproxy.beget.repl.co
but you have to run the database proxy repl first.

1 Like

Hi @python660 !
Would a private repl as a proxy repl work?
Also, if the user forks the repl, a simple nuke will kill the main repl.

a private repl as a proxy would work, however, it is no different than a public repl because it contains the same code as thousands of other forks from @util’s repl. What you should do is add CLI Auth (For transparency I created CLI Auth so I’m promoting it) to your database proxy.
Fork these examples to get started:

Server: https://replit.com/@cliauth/CLIAuth-Database-Server
Client example: https://replit.com/@cliauth/CLIAuth-InkedIn-Client

1 Like

@beget uh don’t do that if you don’t want people to edit your db

yes that is true. I am just about to release CLI Auth so feel free to be an Explorer and try it out!

Awesome, thanks for the heads up. I think I might try to move beyond replit and learn HTML and javascript with maybe like google cloud or google sheets as the database for now…

1 Like