You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/post/waterbase.md
+1-79Lines changed: 1 addition & 79 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,83 +3,5 @@ title: The Easiest Database you could ever need!
3
3
description: As a developer, you might have heard of FireBase. But do you know about.....WaterBase ??
4
4
date: 2022-08-02
5
5
---
6
-
### As a developer, you might have heard of FireBase. But do you know about.....WaterBase ??
7
6
8
-
I've always admired Android in the way of storing persistent data. If you are famaliar with Android Development, you'd know about Shared Preferences. If that's new to you, it is basically a storage utility that Android provides using which you can store data in Key-value form. Shared Preferences are suitable in different situations. For example, when the user’s settings need to be saved or to store data that can be used in different activities within the app.
9
-
10
-
But...we don't get that awesome feature outside the Android environment. Do we? So I decided to create a lightweight storage utility that provides such behavior and can be used on any platform. And voila...[WaterBase](https://github.com/coderGtm/WaterBase) was born ;)
Ok...so here's my explanation. As we all know that 🔥FireBase is a database that is in cloud and can be accessed from anywhere. And so WaterBase is a database on your hard disk that can be accessed from anywhere...just like water🌊...simple and lightweight🪶.
As promised, in the easisest way...WaterBase is currently available in C++ and Python
23
-
24
-
> Talk is cheap. Show me the code.
25
-
26
-
Ok then...here's the Python version
27
-
28
-
```python
29
-
from waterbase import WaterBase
30
-
31
-
# Create / open a database file (creates one if it doesn't exist)
32
-
db = WaterBase("myDatabase")
33
-
34
-
# Save values (Bool / Int / String supported)
35
-
db.SaveBool("is_active", True)
36
-
db.SaveInt("score", 42)
37
-
db.SaveString("username", "gautam")
38
-
39
-
# Load them back (second arg is default value if key missing)
40
-
active = db.LoadBool("is_active", False)
41
-
score = db.LoadInt("score", 0)
42
-
username = db.LoadString("username", "guest")
43
-
44
-
print(active, score, username)
45
-
```
46
-
47
-
And if you rather prefer C++, you're covered:
48
-
49
-
```cpp
50
-
#include"WaterBase.hpp"
51
-
#include<iostream>
52
-
53
-
intmain() {
54
-
WaterBase db("myDatabase");
55
-
56
-
db.SaveBool("is_active", true);
57
-
db.SaveInt("score", 42);
58
-
db.SaveString("username", "gautam");
59
-
60
-
bool active = db.LoadBool("is_active", false);
61
-
int score = db.LoadInt("score", 0);
62
-
std::string user = db.LoadString("username", "guest");
63
-
64
-
std::cout << active << " " << score << " " << user << std::endl;
65
-
return 0;
66
-
}
67
-
```
68
-
69
-
#### Explanation:
70
-
71
-
First we create an instance of the class WaterBase. We provide the name of the WaterBase database to use as parameter. If no database exists by that name, a new one is created.
72
-
73
-
Now let's put some values in our database. WaterBase supports three types of values: Boolean, Integer and String. To save values, use the `db.Save*(key, value)` function.
74
-
75
-
Now if you want to retreive these values, use `db.Load*(key, default_value)` function.
76
-
77
-
That's all...This is the simplest databse you could ever need. You can find the GitHub repository [here.](https://github.com/coderGtm/WaterBase)
78
-
79
-
And one last thing...if you've read till here and are still unsure whether should you use WaterBase or not in a project, then please, please, please drop a comment on the repository's [issue page](https://github.com/coderGtm/WaterBase/issues), describing why you don't wanna use it. It can help the community to make WaterBase a better product, more suited for you.
0 commit comments