- assert isinstance(todo, Todo)
- return todo
-
- @classmethod
- def by_id(cls, db_conn: DatabaseConnection, id_: int | None) -> Todo:
- """Get Todo of .id_=id_ and children (from DB cache if possible)."""
- if id_:
- todo, from_cache = super()._by_id(db_conn, id_)
- else:
- todo, from_cache = None, False
- if todo is None:
- raise NotFoundException(f'Todo of ID not found: {id_}')
- if not from_cache:
- for row in db_conn.exec('SELECT child FROM todo_children '
- 'WHERE parent = ?', (id_,)):
- todo.children += [cls.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT parent FROM todo_children '
- 'WHERE child = ?', (id_,)):
- todo.parents += [cls.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT condition FROM todo_conditions '
- 'WHERE todo = ?', (id_,)):
- todo.conditions += [Condition.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT condition FROM todo_fulfills '
- 'WHERE todo = ?', (id_,)):
- todo.fulfills += [Condition.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT condition FROM todo_undoes '
- 'WHERE todo = ?', (id_,)):
- todo.undoes += [Condition.by_id(db_conn, row[0])]
- assert isinstance(todo, Todo)
+ assert isinstance(todo.id_, int)
+ for t_id in db_conn.column_where('todo_children', 'child',
+ 'parent', todo.id_):
+ # pylint: disable=no-member
+ todo.children += [cls.by_id(db_conn, t_id)]
+ for t_id in db_conn.column_where('todo_children', 'parent',
+ 'child', todo.id_):
+ # pylint: disable=no-member
+ todo.parents += [cls.by_id(db_conn, t_id)]
+ for name in ('conditions', 'enables', 'disables'):
+ table = f'todo_{name}'
+ assert isinstance(todo.id_, int)
+ for cond_id in db_conn.column_where(table, 'condition',
+ 'todo', todo.id_):
+ target = getattr(todo, name)
+ target += [Condition.by_id(db_conn, cond_id)]