Fields
Fields in EffortlessDB are powerful tools for querying and manipulating data. They allow you to specify conditions, sort data, and perform various operations on your database entries.
Properties
field
The field name or names to query. Can be a string for a single field, or a tuple/list for embedded fields.
condition
A function that defines the condition for the entry. It is given the entry's data for the given key and returns if the entry passes. To set this, use a method defined below.
Methods
__init__
Creates a new Field object with the given key. This automatically creates the condition that the field must exist.
equals
Creates a condition that the entry's field is equal to the given value.
greater_than
Creates a condition that the entry's field is greater than the given value.
less_than
Creates a condition that the entry's field is less than the given value.
contains
Creates a condition that checks if the field contains the given value. For strings, it checks if the value is a substring. For lists, it checks if the value is in the list. Case-sensitive by default.
startswith
Creates a condition that checks if the field starts with the given value. Case-sensitive by default.
endswith
Creates a condition that checks if the field ends with the given value.
matches_regex
Creates a condition that checks if the field matches the given regex pattern and regex flags (if given).
between_dates
Creates a condition that checks if the field's date is between the given dates. Valid dates are either datetime objects, strings in the yyyy-mm-dd format, or Unix timestamps.
fuzzy_match
Creates a condition that checks if the field fuzzy matches the given value. Don't use this for exact filtering!
passes
Creates a condition that checks if the field passes the given lambda or function.
is_type
Creates a condition that checks if the field is of the expected type.
Note: Fields in EffortlessDB are Queries with field attributes under the hood. If you want to create a passes condition that receives the entire data of an entry, import and create a Query and pass in a Callable that expects an entire entry dict. You'll need to do input validation yourself.