def test_get_connection(self):
        with patch.object(rethink, 'connect', return_value=None) as \
                connect_method:

            get_connection()

            connect_method.assert_called_once()
            connect_method.assert_called_with(host='localhost', port=28015,
                                              auth_key='', db=DEFAULT_DB_NAME)
    def test_get_connection(self):
        with patch.object(rethink, 'connect', return_value=None) as \
                connect_method:

            get_connection()

            connect_method.assert_called_once_with(host='localhost',
                                                   port=28015,
                                                   auth_key='',
                                                   db=DEFAULT_DB_NAME)
Exemple #3
0
    def delete_specific(table_name, filters=None):
        """
        Deletes all records in a table matching the filter
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return rethink.table(table_name).filter(filters).delete().run(conn)
Exemple #4
0
    def delete_specific(table_name, filters=None):
        """
        Deletes all records in a table matching the filter
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return rethink.table(table_name).filter(filters).delete().run(conn)
Exemple #5
0
def drop_database():
    """
    Deletes the RethinkDB database
    """
    try:
        with get_connection() as conn:
            rethink.db_drop(DEFAULT_DB_NAME).run(conn)
    except (RqlRuntimeError, RqlDriverError) as err:
        raise err
Exemple #6
0
def drop_database():
    """
    Deletes the RethinkDB database
    """
    try:
        with get_connection() as conn:
            rethink.db_drop(DEFAULT_DB_NAME).run(conn)
    except (RqlRuntimeError, RqlDriverError) as err:
            print(err.message)
Exemple #7
0
    def list_all(table_name, order_by='epoch', filters=None):
        """
        Gets a full list of records - no pagination.
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return list(rethink.table(table_name)
                        .order_by(order_by).filter(filters).run(conn))
Exemple #8
0
    def query(table_name, order_by='epoch', filters=None):
        """
        Query for record(s)
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return rethink.table(table_name)\
                .order_by(order_by).filter(filters).run(conn)
Exemple #9
0
    def query(table_name, order_by='epoch', filters=None):
        """
        Query for record(s)
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return rethink.table(table_name)\
                .order_by(order_by).filter(filters).run(conn)
Exemple #10
0
    def list_all(table_name, order_by='epoch', filters=None):
        """
        Gets a full list of records - no pagination.
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return list(
                rethink.table(table_name).order_by(order_by).filter(
                    filters).run(conn))
Exemple #11
0
    def list(table_name, start, limit, order_by='epoch', filters=None):
        """
        Gets a list of records, meant for pagination.
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return rethink.table(table_name)\
                .filter(filters).order_by(order_by) \
                .slice(start, limit).run(conn)
Exemple #12
0
    def list(table_name, start, limit, order_by='epoch', filters=None):
        """
        Gets a list of records, meant for pagination.
        """
        if not filters:
            filters = {}

        with get_connection() as conn:
            return rethink.table(table_name)\
                .filter(filters).order_by(order_by) \
                .slice(start, limit).run(conn)
Exemple #13
0
    def insert(table_name, **kwargs):
        """
        Inserts a new record. id and epoch are common to all records.
        """
        if 'id' not in kwargs:
            kwargs['id'] = str(uuid.uuid4())

        kwargs['epoch'] = time()

        with get_connection() as conn:
            rethink.table(table_name).insert(kwargs).run(conn)
        return kwargs
Exemple #14
0
    def insert(table_name, **kwargs):
        """
        Inserts a new record. id and epoch are common to all records.
        """
        if 'id' not in kwargs:
            kwargs['id'] = str(uuid.uuid4())

        kwargs['epoch'] = time()

        with get_connection() as conn:
            rethink.table(table_name).insert(kwargs).run(conn)
        return kwargs
Exemple #15
0
    def update(table_name, record_id=None, filters=None, updates=None):
        """
        Perform an update on one more fields
        """
        if not filters:
            filters = {}
        if not updates:
            updates = {}

        with get_connection() as conn:
            if record_id:
                return rethink.table(table_name).get(record_id)\
                    .update(updates).run(conn)
            else:
                return rethink.table(table_name).filter(filters)\
                    .update(updates).run(conn)
Exemple #16
0
    def update(table_name, record_id=None, filters=None, updates=None):
        """
        Perform an update on one more fields
        """
        if not filters:
            filters = {}
        if not updates:
            updates = {}

        with get_connection() as conn:
            if record_id:
                return rethink.table(table_name).get(record_id)\
                    .update(updates).run(conn)
            else:
                return rethink.table(table_name).filter(filters)\
                    .update(updates).run(conn)
Exemple #17
0
def create_database():
    """
    Creates a new RethinkDB database with tables if it doesn't already exist
    """
    try:
        with get_connection() as conn:
            db_list = rethink.db_list().run(conn)

            if DEFAULT_DB_NAME not in db_list:
                # Default db doesn't exist so add it
                rethink.db_create(DEFAULT_DB_NAME).run(conn)

            table_list = rethink.db(DEFAULT_DB_NAME).table_list().run(conn)

            for table_name in DEFAULT_TABLE_NAMES:
                if table_name not in table_list:
                    # Add the missing table(s)
                    rethink.db(DEFAULT_DB_NAME).table_create(table_name)\
                        .run(conn)

    except (RqlRuntimeError, RqlDriverError) as err:
        raise err
Exemple #18
0
def create_database():
    """
    Creates a new RethinkDB database with tables if it doesn't already exist
    """
    try:
        with get_connection() as conn:
            db_list = rethink.db_list().run(conn)

            if DEFAULT_DB_NAME not in db_list:
                # Default db doesn't exist so add it
                rethink.db_create(DEFAULT_DB_NAME).run(conn)

            table_list = rethink.db(DEFAULT_DB_NAME).table_list().run(conn)

            for table_name in DEFAULT_TABLE_NAMES:
                if table_name not in table_list:
                    # Add the missing table(s)
                    rethink.db(DEFAULT_DB_NAME).table_create(table_name)\
                        .run(conn)

    except (RqlRuntimeError, RqlDriverError) as err:
            print(err.message)
Exemple #19
0
 def get(table_name, record_id):
     """
     Get a single record based on id.
     """
     with get_connection() as conn:
         return rethink.table(table_name).get(record_id).run(conn)
Exemple #20
0
 def delete(table_name, record_id):
     """
     Deletes a single record in a specified table
     """
     with get_connection() as conn:
         return rethink.table(table_name).get(record_id).delete().run(conn)
Exemple #21
0
 def delete_all(table_name):
     """
     Deletes all records in a specified table
     """
     with get_connection() as conn:
         return rethink.table(table_name).delete().run(conn)
Exemple #22
0
 def get(table_name, record_id):
     """
     Get a single record based on id.
     """
     with get_connection() as conn:
         return rethink.table(table_name).get(record_id).run(conn)
Exemple #23
0
 def delete_all(table_name):
     """
     Deletes all records in a specified table
     """
     with get_connection() as conn:
         return rethink.table(table_name).delete().run(conn)
Exemple #24
0
 def delete(table_name, record_id):
     """
     Deletes a single record in a specified table
     """
     with get_connection() as conn:
         return rethink.table(table_name).get(record_id).delete().run(conn)