a simple python local database
to get started in an easy way... let's start by creating a new instance of the Data Base
from EasyDB import EasyDB, DB
db = EasyDB(autoSave=True)
collection: DB = db.newCollectionwhat is "autoSave" of the DB instance?
it is an automatic backup method, which you can activate or deactivate... having this system activated... your database is less vulnerable to a total loss of data, in case something unforeseen occurs
You can see some examples on: Create Items
for you to create objects in the database, it is also very easy... see below
collection.create("hello", "word")Just that? ya
it is worth noting. To create objects in the database in a specific way you can do:
collection.create("hello", {})
collection.create("how are you?","good, and you?", "hello"){
"hello": {
"how are you?": "good, and you?"
}
}the path must be divided by dots
collection.create("hello", {})
collection.create("how are you?", {}, "hello")
collection.create("good, and you?", "me also", "hello.how are you?")You can see some examples on: Delete Items
to delete an object you just use the .delete method. see below
collection.delete("path")You can see some examples on: Filtering Items
To get start filtering objects, you must create a filter, lambda or a normal def
def filter(arg): #receive a db object
#your stuff, but must return a bool
return arg == 1
#or
filter = lambda x: x == 1
and then, call
for i in collection.filter(filter):
print(i.path, i.value)filtering method returns 2 attributes. path and value
value return the value what returns True path return the path of the value ("path.to.value")
You can see some examples on: Finding Items
Find item is like the filtering method... but returns only one value
result = collection.find(filter)
print(result.path, result.value)You can see some examples on: Getting Items
To get a item, you can just type:
print(collection.get(path if has))You can see some examples on: Save Database
to save your database, you jsut type
collection.save()You can see some examples on: Load Json
to load you json file to db you just type
collection.load("<path> or <file stream>", mode="set"| "append" )apppend: append data to database
set: sets the data from de json as database
if autoSave is off... you can store any type of object. however when trying to save, it will corrupt your database
- sync and local db
- load modes
- async DB