Turn on explorer mode to use it!
Hello everyone! Repl.it just announced a new way to host your databases. They have created their own database type. It's unlike any other SQL/noSQL database: It is JSON based!!!
So, with help from @masfrost, I have created an npm package for it! It contains the native
curl functions, and includes more (like emptying database, setting automatic types for values and more!) Also along the way, I learned testing with jest...
Also, I got the hacker plan!
Without further ado, here are the docs!
1) Click on the floppy disk:
This is the homepage for your database. You can view storage usage and amount of keys.
2) Click on the box icon:
3) Copy and paste this code into the editor (if all you want is a minimalistic template).
4) Now, you are ready to set some commands! Inside the
async function, you can do some methods. For our tutorial, we will make a
what do you think of the node.js engine survey.
Some quick docs
you can leave out the
raw part, but if you set
raw to false, you will either get an object, or an error (the data wasn't valid json)
getting all data as an object
delete all data
Add this to your code:
This just gets our form ready. Remember the
async because we are using
await calls here.
6) Save to database
Quite easy. We just refer to our
set method in the docs.
7) Get all data
Now, we can use
client.getAll to accomplish this!
8) Parse the data
Right now our data is just an object, let's make it human-readable!
9) And that's it! We have gone through almost all of what you will be using for a database (with delete as an exception). I can't wait to see what you will make with the client!
- Make it so if the user entered a name that is already in the database, don't save to the database. (hint:
- Add colors!!
- Get a specific user's entry
Have a great day!
Ask in the comments below if you have any questions ;)
I have a few questions, and i am kinda new so sorry if that's dumb questions but...
- What type of data can you store in your database? I know you can do it with strings, but can you do it with integers, floats or booleans?
- The line to import the database in your example is :
However the line to import the database that repl gives me is :
Does that mean that some stuff from the code is outdated? Or does your example still work?
- Can you create multiple databases in a single repl? I am trying to code a game in a discord bot that would remember both the gold the user has and the experience points won. I tried something like
Would it be possible to manipulate both databases like that?
- [SOLVED] I don't know why but a lot of times the operations with the database are done out of order. For example, i have this program that's supposed to delete the database then add 2 values/keys and once it does so it logs them in the console :
However, when I run it, the logs changes on every run, and I get sometimes this log :
Sometimes I get...
And it changes exery time. What is the cause of that and how can I fix it? (Here is the repl's link : https://repl.it/@helloyanis/testdb#index.js )
Nevermind I solved it, jut had to add
after the line of code that clears the database. The link has the fixed code if someone wants it
- Any JSON serializable object.
- It only differs by name, this is an older tutorial, after replit adapted by library they must have changed how you defined things to be slightly more precise. There haven't been any breaking changes yet so it should be correct.
- psst don't do that one db client is good, but you can have multiple. It might cause some data races
Why am I still asking questions about this?
This has stumped me for a long, long time
How does the code know that the
user is the same as
name? And for the
data[user], how does it know that that is
ans??? (In this chunk of code):
Would you mind changing the implementation of
setAll so it is more efficient? Currently, it waits for the fetching/setting the value for each key before continuning with the next key:
This could be improved by using something like this:
Hello. Thanks for your suggestion! Currently, I'm doing it this way is because of concerns about what the API can handle and not handle.
Promise.all executes them all at the same time, while the
await method will do it one-by-one. A bit slower, but until sid gets back,
this will be the implementation for now. @cherryblossom00