Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
7

Host SQL database on repl.it

CodeLongAndPros
CodeLongAndPros

How would I host a SQL database on a SQLite repl, and access it from JS on another repl?

3 years ago

Voters

Comments

TopNew
2
Gellehaiak
Gellehaiak

Sorry to bring this up; Yes, you can. In every class, you need to call the database to create its DatabaseHelper DB = new DatabaseHelper(this); and then DB. Open (); and after that, DB.yourMethodQuery to call the method you have in your DatabaseHelper.
It's best to have a global DatabaseHelper variable DB and call it at creation to create an instance of DB = new DatabaseHelper(this), and then you can call DB.something anywhere in the class. If that doesn't work, then ask the
https://www.devart.com/dbforge/postgresql/studio/ for help.

1 year ago
1
Coder100
Coder100

Hello, to do that, use the sqlite3 package.
Click me
They have some nice docs and it's actively maintained :)

Cons

There are way too many callbacks for each function kind of annoying, but you can use promises to make a workaround using await

3 years ago
1
CodeLongAndPros
CodeLongAndPros

@Coder100
Sorry, if I was not clear, but I was wondering how I can connect to the database from a different repl. Also, I'm using vanilla JS. I'm making a website and need SQL.

3 years ago
1
Coder100
Coder100

you would have to use sqlite3 to use write and parse binary data, and a sqlite3 repl is basically a database sandbox, so they aren't really useful for a full-blown database.

@CodeLongAndPros

3 years ago
1
johnnghabs
johnnghabs

@Coder100

Necroposting but what you could do, if it's entirely internal, is make a flask that accepts requests and runs those sql commands.

2 years ago
1
Coder100
Coder100

but remember this is not python, it's a sqlite database playground, all the adat is stored in memory, it gets cleared each time you run!

@johnnghabs

2 years ago
1
Coder100
Coder100

also maybe try using that sqlite3 lib everyone was talking about

@CodeLongAndPros

2 years ago
1
johnnghabs
johnnghabs

@Coder100

If the data is cleared every run, you forgot to commit them. On this note, you're not limited to a sqlite3, you can use python and just import sqlite3 lib there

2 years ago
1
CodeLongAndPros
CodeLongAndPros

@johnnghabs
No, replit has problems storing progomatically-written files. Why else did they create replitdb?

2 years ago
2
johnnghabs
johnnghabs

@CodeLongAndPros
I'm quite fascinated; what happens with replit if one tries to use a SQL db? AFAIK replitdb was designed for easier usage as it doesn't have the SQL learning curve.

2 years ago
1
CodeLongAndPros
CodeLongAndPros

@johnnghabs
It'll work, but it's not deterministic— a change committed may or may not show up in the database (or stay there)

2 years ago
Load more