Ask coding questions

← Back to all posts
Host SQL database on repl.it
CodeLongAndPros

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

Voters
DipakHarkal
CodeLongAndPros
Comments
hotnewtop
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

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.

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

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.

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

Coder100

also maybe try using that sqlite3 lib everyone was talking about @CodeLongAndPros

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

CodeLongAndPros

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

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.

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)