Module pyfreedb.row.models

Classes

class BoolField (column_name: str = '', is_formula: bool = False)
Expand source code
def __get__(self, obj: Any, _: Any) -> Optional[T]:
    value = getattr(obj._data, self._field_name)
    return cast(Optional[T], value)

A field for storing boolean values.

Defines the internal representation of the model fields. This is where we can put per field custom config as well.

Args

column_name
an alias of the field name to represent the actual column name in the sheets.
is_formula
a boolean indicating if the field is a formula or not. Only applicable for StringField.

Ancestors

  • pyfreedb.row.models._Field
  • typing.Generic
class FloatField (column_name: str = '', is_formula: bool = False)
Expand source code
def __get__(self, obj: Any, _: Any) -> Optional[T]:
    value = getattr(obj._data, self._field_name)
    return cast(Optional[T], value)

A field for storing floating point number values.

Defines the internal representation of the model fields. This is where we can put per field custom config as well.

Args

column_name
an alias of the field name to represent the actual column name in the sheets.
is_formula
a boolean indicating if the field is a formula or not. Only applicable for StringField.

Ancestors

  • pyfreedb.row.models._NumberField
  • pyfreedb.row.models._Field
  • typing.Generic
class IntegerField (column_name: str = '', is_formula: bool = False)
Expand source code
def __get__(self, obj: Any, _: Any) -> Optional[T]:
    value = getattr(obj._data, self._field_name)
    return cast(Optional[T], value)

A field for integer number values.

Defines the internal representation of the model fields. This is where we can put per field custom config as well.

Args

column_name
an alias of the field name to represent the actual column name in the sheets.
is_formula
a boolean indicating if the field is a formula or not. Only applicable for StringField.

Ancestors

  • pyfreedb.row.models._NumberField
  • pyfreedb.row.models._Field
  • typing.Generic
class Model (*args: Any, **kwargs: Any)
Expand source code
class Model(metaclass=_Meta):
    """Base class of model class to be used by GoogleSheetRowStore.

    Client should not use this class directly, inherit this class to define your own model instead.

    >>> class Person(Model):
    ...     name = StringField()
    ...     age = IntegerField()
    """

    _fields: Dict[str, Union[IntegerField, FloatField, BoolField, StringField]]

    def _validate_type(self) -> None:
        for field in self._fields:
            # Trigger the validation by reassigning the value to itself.
            setattr(self, field, getattr(self, field))

Base class of model class to be used by GoogleSheetRowStore.

Client should not use this class directly, inherit this class to define your own model instead.

>>> class Person(Model):
...     name = StringField()
...     age = IntegerField()
class NotSet
Expand source code
class NotSet:
    """A dummy class to differentiate between fields that are not set and None.

    >>> model_obj = store.select("name").excute()[0]
    >>> model_obj.name is NotSet
    False
    >>> model_obj.age is NotSet
    True
    """

A dummy class to differentiate between fields that are not set and None.

>>> model_obj = store.select("name").excute()[0]
>>> model_obj.name is NotSet
False
>>> model_obj.age is NotSet
True
class StringField (column_name: str = '', is_formula: bool = False)
Expand source code
def __get__(self, obj: Any, _: Any) -> Optional[T]:
    value = getattr(obj._data, self._field_name)
    return cast(Optional[T], value)

A field for storing string values.

Defines the internal representation of the model fields. This is where we can put per field custom config as well.

Args

column_name
an alias of the field name to represent the actual column name in the sheets.
is_formula
a boolean indicating if the field is a formula or not. Only applicable for StringField.

Ancestors

  • pyfreedb.row.models._Field
  • typing.Generic