Advanced Usage

For those who want more control and advanced features, Effortless offers powerful capabilities. You should have a strong understanding of Python for this! Here's how to use Effortless with advanced features:

You'll Need These

from effortless import EffortlessDB, EffortlessConfig, Field, Query

Creating a Custom Database Instance

You can create a Effortless instances with custom directories and filenames.

db = EffortlessDB("advanced_db") db.set_directory("/path/to/custom/directory")

Configuring the Database

You can further customize the database with a configuration:

config = EffortlessConfig(readonly=True) db.configure(config) # The database contents are now read-only db.add({"Anything": "will not work"}) # Raises an error

Adding Entries

You can put pretty much anything in an entry, and Effortless will interperet structures like dates, lists, etc.

db.add({"id": 1, "name": "Eve", "skills": ["Python", "JavaScript"], "joined": "2023-01-15"}) db.add({"id": 2, "name": "Frank", "skills": ["Java", "C++"], "joined": "2023-02-20"}) db.add({"id": 3, "name": "Grace", "skills": ["Python", "Ruby"], "joined": "2023-03-10"})

Complex Filtering

Use advanced filtering techniques with Fields to find specific entries. For example, to find anyone who knows Python and joined in Jan/Feb:

db.filter( ‎ Field("skills").contains("Python") & ‎ Field("joined").between_dates("2023-01-01", "2023-02-28") )

Batch Updates

You can update multiple entries that match a condition:

db.batch( ‎ {"status": "experienced"}, ‎ Field("skills").contains("Python") & Field("joined").less_than("2023-03-01") )

Erasing Multiple Entries

You can also erase to remove multiple entries that match a condition:

db.erase(Field("skills").contains("Java"))

Custom conditions

You can write your own complex checks and use them in Field.passes().

def is_experienced(skills): ‎ return len(skills) > 3 result = db.filter(Field("skills").passes(is_experienced))

These advanced features allow you to create more complex database structures, perform intricate queries, and have finer control over your database configuration.

Basic Usage Technical Docs