Skip to content
← Back to Community
How Do I Access Other Repl.It Databases From Different Repls?
Profile icon
Ste942

I just want to get one value for one key. I am programming in Node.js and have little to no experience with external APIs, but I tried played around with the Repl.it database URL using a API testing tool (ReqBin) and wasn't able to accomplish anything.

Am I supposed to use the replit-database package to access it or do a GET request to pull data from it. Any help would be appreciated.

Answered by RayhanADev [earned 5 cycles]
View Answer
Voters
Profile icon
267349
Profile icon
Ste942
Comments
hotnewtop
Profile icon
RayhanADev

Heylo @Ste942

There’s a flaw in how they coded ReplDB and integrated it with the Repl so I’ll make it short:

  1. Open the Repl which DB you want to use
  2. Open the Shell by pressing Ctrl+Shift+S
  3. In the shell type printenv. You will see a lotta stuff pop up. Look for the variable named REPLIT_DB_URL. Note that, copy it, whatever
  4. In the other Repl type create a client like normal except with ONE small change:
const client = new Client(LINK YOU COPIED FROM BEFORE)

and now it should work 😊! Let me know how it goes!

Profile icon
Umar-FaruqAkinw

@RayhanADev Does this work for java databases??

Profile icon
bigboyyyyyyyy69

@RayhanADev I see you provided an answer but how could I do this in python?

Profile icon
RayhanADev

@bigboyyyyyyyy69 Hiya! Just click the tab on the left with the database symbol and it should show a line similar to the one above. Insert that and follow the same steps :).

Profile icon
bigboyyyyyyyy69

@RayhanADev oh I can only see how to do it in the native db not with a link..

Profile icon
RayhanADev

@bigboyyyyyyyy69 pass in the link as a parameter when creating the db :)

Profile icon
bigboyyyyyyyy69

@RayhanADev but u dont create the db in python.. right? could you send an example pls..

Profile icon
RayhanADev

@bigboyyyyyyyy69 sure in a few

Profile icon
bigboyyyyyyyy69

@RayhanADev yayy thank you :D

Profile icon
bigboyyyyyyyy69

@RayhanADev did u figure it out? :D

Profile icon
RayhanADev

@bigboyyyyyyyy69 yep! I had to dig around Github and find the database module. Here's what you do:

from replit import db db.db_url = "your-db-url-here"
Profile icon
bigboyyyyyyyy69

@RayhanADev thank you!!

Profile icon
bigboyyyyyyyy69

@RayhanADev Also I just thought of something: Changing the value "REPLIT_DB_URL" with os or smth.. is that even possible? Just curious lol

Profile icon
RayhanADev

@bigboyyyyyyyy69 hmm, I do not know ƪ(˘⌣˘)ʃ. Try it and lmk how it goes :D

Profile icon
bigboyyyyyyyy69

Ok soon I'll do it :D @RayhanADev

Profile icon
Coder100

Well I just want to say you can't.

The database URL will change so you will have to regenerate each time.
Anyways, I have an option so you can pass the url when making a client:

const client = require("@replit/database"); const DB = new client("[INSERT-URL-HERE]");

and to find that url, just do:

process.env.REPLIT_DB_URL

in the repl of your choice.

Profile icon
Ste942

@Coder100 Thanks. Again, I am a beginner so I apologize if I am not following here, but is the regenerating URL the issue?

Also, do you happen to know how often the URLs regenerate? (every hour, every day, every month, etc)

Profile icon
Coder100

@Ste942 once a month

Profile icon
efish

You can't. Just make the first repl with a database a file in the second repl.

Profile icon
Ste942

@Efish1824 I don't know if its not possible, since on the Repl.it Database page on the docs, (https://docs.repl.it/misc/database) the very bottom section has a tiny place where it suggests it is possible.