-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Welcome to the LiteJsonDb Wiki! Here, we showcase tutorials and guides on how to make the most out of your LiteJsonDb experience. Whether you're a seasoned developer or just starting, we've got something for everyone. Today, we're diving into a super cool feature that makes your life easier: the increment
functionality. Because who doesn't love a good shortcut?
The increment
feature is all about simplifying your life. It allows you to effortlessly increase numerical values in your database. Whether it's updating scores, counters, or any other numeric fields, increment
has got you covered.
Ready to add some points or counts? Here's how you do it:
# Let's init data
db.set_data("users/1", {"name": "Max", "score": 15})
# Edit Data
db.edit_data("users/1", {"increment": {"score": 5}})
Boom! Just like that, the score for user is incremented by +5
. It's that easy!
Paths are your best friend. They allow you to navigate and manage your data with ease and precision. Let's dive into how you can harness the full power of paths to organize and manipulate your data like a pro!
Paths in LiteJsonDb work similarly to file paths in a filesystem. They are used to access and manage nested data structures. By using the /
separator, you can dive into nested objects and collections effortlessly. Here's a quick breakdown:
- Root Level: The topmost level of your data structure.
- Nested Levels: Levels of data within objects or arrays.
Let's say you have a user collection and want to access the data of a specific user. Here's how you can do it:
db.get_data("users/1")
This command will fetch the data for the user with ID 1
. The path users/1
navigates to the users
collection and then selects the user with the key 1
.
Want to go deeper? No problem! You can access deeply nested data by simply extending the path. For example:
db.get_data("users/1/profile/age")
This command retrieves the age
from the profile
of user 1
. You can use this approach to access any level of nested data.
Paths are not just for accessing dataβthey're also powerful for manipulating it. Here's how you can use paths to modify your data:
You can set data at any path. For instance, to update a user's profile:
db.set_data("users/1/profile", {"name": "Max", "age": 30})
This sets the profile information for user 1
. If the profile
object didn't exist, it would be created.
Editing specific parts of your data is a breeze with paths:
db.edit_data("users/1/profile", {"name": "MaxV3"})
This modifies the name
in the profile
of user 1
. The rest of the data remains untouched.
-
Non-Existent Paths: If you try to access a path that doesn't exist, LiteJsonDb will return
None
. You can use this behavior to check if data exists before performing operations. -
Creating Nested Data: If you set data on a non-existent nested path, LiteJsonDb will automatically create the necessary structure for you. For example:
db.set_data("users/2/settings/preferences", {"theme": "dark"})
This will create the entire path structure if it doesn't exist, setting the
preferences
for user2
.