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
12

ReplDBManager || A Java Client For ReplDB

EpicGamer007
EpicGamer007

ReplDBManager V 1.0

ReplDBManager is a client for replers to use to easily manage the Database in their java repl project.

This was created by
@AbhayBhat

The creator has also received help from:

  • @Scoder12
    - Helped with getting data from the Database(Setting up the network connection)
  • @Coder100
    - Also helped with getting data from the Database(Setting up the network connection)
  • @Jakman
    - Helped with Testing and feedback
  • @SixBeeps
    - Helped with fixing and improving the client

Setting up ReplDBManager:

As of V 1.0, the only ways to get ReplDBManager into your repl currently is to fork this repl or copy-pasting the code in a file called ReplDBManager.java. Source can be found here.

A jar is planned to come out shortly.

Using the Class

Setting it up in your project

Declaring the Client is like so:

ReplDBManager client = new ReplDBManager(System.getenv("REPL_DB_URL"));

Pass in the url to your repl database by by using System.getenv().

If you are using this on your os, remember to get the link from here then use it from your computer because REPL_DB_URL will most likely not be one of your environment variables already

Noteable Instance variables

  • boolean toUpper - If true, all new key-value pairs will be converted to uppercase before going into the database. Set to false by default

Using it's methods

***IT IS IMPORTANT TO NOTE THAT THESE METHODS ALL throws IOException, InterruptedException ***

The available methods in ReplDBManager as of V 1.0 is:

  • void setValue(String key, String value) - sets the key to value in the database. If key is not already present, it will be created
  • void setValues(Map<String, String> things) - sets all the key's in the Map to the value's in the map. Example:
Map<String, String> toAdd = new HashMap<String, String>(); toAdd.put("KEYONE", "AVALUE"); toAdd.put("KEYTWO", "ANOTHERVALUE"); client.setValues(toAdd);
  • String getValue(String key) - returns the value associated with the key
  • String[] getKeys() - returns all keys in the database
  • HashMap<String, String> getAll() - returns every key with every value associated with the key
  • void deleteValue(String key) - deletes the value associated with the key and the key from the database
  • void deleteValues(String[] keys) - deletes all the values associated with the keys and the key from the database
  • void deleteAll() - Deletes ALL the key-value pairs from the database
  • void setToUpper(boolean newB) - sets the toUpper variable to newB
  • boolean getToUpper(boolean newB) - gets the variable toUpper

Notes: If parameters passed to any of the setValue methods contain a ' ', it will be converted to '-'. Example:

client.setValue("SPACE TEST", "What will happen to this because of the spaces?"); System.out.println(client.getValue("SPACE-TEST"));

Will print:

What-will-happen-to-this-because-of-the-spaces?

That is all. I hope y'all enjoy it.

Happy Coding :D

Edit: Added no-arg constructor which initializes url to database with System.getenv("REPLIT_DB_URL");.
Edit: You need Java 11 for this to work. The java.net.http packages are only a part of hava 11

2 years ago

Voters

Comments

TopNew
1
EpicGamer007
EpicGamer007

FOR ANYONE READING THIS AFTER 6/15/2021, THE ORIGINAL REPLDBMANAGER HAS BEEN DELETED, PLEASE DIRECT YOURSELVES TO https://replit.com/@EpicGamer007/ReplDBClient

1 year ago
1
plscodeinjava
plscodeinjava

@AbhayBhat

I need help with this, I am getting an error:

image

2 years ago
1
EpicGamer007
EpicGamer007

@amaddentcsec
, you have to use java 11. reload the tab and tell me which version of java it says

2 years ago
1
EpicGamer007
EpicGamer007

@amaddentcsec

It should look like this:

image

2 years ago
1
EpicGamer007
EpicGamer007

@amaddentcsec
, yea u need to change the java version

2 years ago
1
plscodeinjava
plscodeinjava

@AbhayBhat

Can you help me with this?

2 years ago
1
EpicGamer007
EpicGamer007

@AbhayBhat
, sorry, online class rite now :( maybe later. Try searching it up though or ask in ask

2 years ago
1
Jakman
Jakman

Good job. You are almost at my level. You are doing amazingly. You've grown so much since i first started teaching you. I want you to beat me in the knowledge of java.

2 years ago
1
EpicGamer007
EpicGamer007

@Jakman
, wait, when did u decide ur better than me? lol

Edit: It's a lot of google too.

2 years ago
1
Jakman
Jakman

@AbhayBhat
i remember teaching you some basics just a few months ago.
Helping you with the concepts. I can see though that you are challenging my skill. And i can see that one day you will know more about java than me

2 years ago
1
EpicGamer007
EpicGamer007

@Jakman
, ok... But i mean, by basics. What exactly do u mean, when i signed up for repl, i already had a good grasp on the basics.

2 years ago
1
Jakman
Jakman

@AbhayBhat
Not exactly basics. Really just cool tech that you could use to your advantage. I also remember helping you with the private and protected keywords.

2 years ago
1
EpicGamer007
EpicGamer007

@Jakman
, oh yea, thanks for that :D. It just.. my pride wont let me think that i was worse than u, uhhhhhhhh. sorry, just venting on repl

2 years ago
1
Scoder12
Scoder12

Maybe you should be able to construct with no arguments and it will use the environment variable for you.

2 years ago
1
EpicGamer007
EpicGamer007

@Scoder12
, that is possible but the problem with that is what if someone is using theis from their own computer?(Most people probably won't but there is a chance). Then the environment variable would not be there, and there is a chance it could break, this way, someone could get a link from one of their repls doing something like echo $REPLIT_DB_URL, get the link, then paste it when initializing the variable making it accessible even when you are not on repl.it

2 years ago
1
EpicGamer007
EpicGamer007

@Scoder12
, I guess I can add a no-arg constructor so that if there is no link initialized, it will just automatically do System.getenv().

2 years ago
1
Scoder12
Scoder12

@AbhayBhat
Thats why you keep the current constructor as well. You can have both.

2 years ago
1
EpicGamer007
EpicGamer007

@Scoder12
, method and constructor overloading is amazing

2 years ago
1
Coder100
Coder100

nice!! C# time

2 years ago
1
SixBeeps
SixBeeps

@Coder100
I'll make one that's better than yours good luck with that!

2 years ago
1
EpicGamer007
EpicGamer007

@SixBeeps
, good luck to you as well!

2 years ago
Load more