Example #1
0
def drop_fork(conn, block_num):
    """Deletes all resources from a particular block_num
    """
    block_results = (
        r.table("blocks")
        .filter(lambda rsc: rsc["block_num"].ge(block_num))
        .delete()
        .run(conn)
    )

    resource_results = (
        r.table_list()
        .for_each(
            lambda table_name: r.branch(
                r.eq(table_name, "blocks"),
                [],
                r.eq(table_name, "auth"),
                [],
                r.table(table_name)
                .filter(lambda rsc: rsc["start_block_num"].ge(block_num))
                .delete(),
            )
        )
        .run(conn)
    )

    return {k: v + resource_results[k] for k, v in block_results.items()}
Example #2
0
    def drop_fork(self, block_num):
        """Deletes all resources from a particular block_num
        """
        block_results = r.db(self._name).table('blocks')\
            .filter(lambda rsc: rsc['block_num'].ge(block_num))\
            .delete()\
            .run(self._conn)

        resource_results = r.db(self._name).table_list()\
            .for_each(
                lambda table_name: r.branch(
                    r.eq(table_name, 'blocks'),
                    [],
                    r.eq(table_name, 'auth'),
                    [],
                    r.db(self._name).table(table_name)
                    .filter(lambda rsc: rsc['start_block_num'].ge(block_num))
                    .delete()))\
            .run(self._conn)

        return {k: v + resource_results[k] for k, v in block_results.items()}
Example #3
0
def rethinkdb_date_greater(greater_date, comparison_date, relaxed_interval):
    return r.branch(
        r.lt(greater_date[0], comparison_date[0]), False,
        r.eq(greater_date[0], comparison_date[0]),
        r.branch(
            r.eq(greater_date[1], 'XX').or_(r.eq(comparison_date[1], 'XX')),
            relaxed_interval, r.lt(greater_date[1], comparison_date[1]), False,
            r.eq(greater_date[1], comparison_date[1]),
            r.branch(
                r.eq(greater_date[2], 'XX').or_(r.eq(comparison_date[2],
                                                     'XX')), relaxed_interval,
                r.lt(greater_date[2], comparison_date[2]), False, True), True),
        True)
Example #4
0
def rethinkdb_date_greater(greater_date, comparison_date, relaxed_interval):
    return r.branch(
        r.lt(greater_date[0], comparison_date[0]),
        False,
        r.eq(greater_date[0], comparison_date[0]),
        r.branch(
            r.eq(greater_date[1], "XX").or_(r.eq(comparison_date[1], "XX")),
            relaxed_interval,
            r.lt(greater_date[1], comparison_date[1]),
            False,
            r.eq(greater_date[1], comparison_date[1]),
            r.branch(
                r.eq(greater_date[2], "XX").or_(r.eq(comparison_date[2], "XX")),
                relaxed_interval,
                r.lt(greater_date[2], comparison_date[2]),
                False,
                True,
            ),
            True,
        ),
        True,
    )