def renew_drivers_license(transaction_executor, valid_from, valid_to,
                          license_number):
    """
    Renew the ValidFromDate and ValidToDate of a driver's license.

    :type transaction_executor: :py:class:`pyqldb.session.executor.Executor`
    :param transaction_executor: An Executor object allowing for execution of statements within a transaction.

    :type valid_from: :py:class:`datetime.datetime`
    :param valid_from: The new valid-from date.

    :type valid_to: :py:class:`datetime.datetime`
    :param valid_to: The new valid-to date.

    :type license_number: str
    :param license_number: The license number for the driver's license to renew.

    :raises RuntimeError: If no driver's license was updated.
    """
    logger.info(
        'Renewing license with license number: {}...'.format(license_number))
    update_valid_date = 'UPDATE DriversLicense AS d SET d.ValidFromDate = ?, d.ValidToDate = ? WHERE d.LicenseNumber ' \
                        '= ?'
    parameters = [
        convert_object_to_ion(valid_from),
        convert_object_to_ion(valid_to),
        convert_object_to_ion(license_number)
    ]
    cursor = transaction_executor.execute_statement(update_valid_date,
                                                    parameters)
    logger.info('DriversLicense Document IDs which had licenses renewed: ')
    list_of_licenses = get_document_ids_from_dml_results(cursor)
    for license in list_of_licenses:
        logger.info(license)
    return list_of_licenses
Example #2
0
def renew_drivers_license(driver, valid_from, valid_to, license_number):
    """
    Renew the ValidFromDate and ValidToDate of a driver's license.

    :type driver: :py:class:`pyqldb.driver.qldb_driver.QldbDriver`
    :param driver: An instance of the QldbDriver class.

    :type valid_from: :py:class:`datetime.datetime`
    :param valid_from: The new valid-from date.

    :type valid_to: :py:class:`datetime.datetime`
    :param valid_to: The new valid-to date.

    :type license_number: str
    :param license_number: The license number for the driver's license to renew.

    :raises RuntimeError: If no driver's license was updated.
    """
    logger.info(
        'Renewing license with license number: {}...'.format(license_number))
    update_valid_date = 'UPDATE DriversLicense AS d SET d.ValidFromDate = ?, d.ValidToDate = ? WHERE d.LicenseNumber ' \
                        '= ?'
    cursor = driver.execute_lambda(lambda executor: executor.execute_statement(
        update_valid_date, convert_object_to_ion(valid_from),
        convert_object_to_ion(valid_to), convert_object_to_ion(license_number))
                                   )
    logger.info('DriversLicense Document IDs which had licenses renewed: ')
    list_of_licenses = get_document_ids_from_dml_results(cursor)
    for license in list_of_licenses:
        logger.info(license)
    return list_of_licenses
Example #3
0
def insert_documents(transaction_executor, table_name, documents):

    logger.info(
        'Inserting some documents in the {} table...'.format(table_name))
    statement = 'INSERT INTO {} ?'.format(table_name)
    cursor = transaction_executor.execute_statement(
        statement, [convert_object_to_ion(documents)])
    list_of_document_ids = get_document_ids_from_dml_results(cursor)

    return list_of_document_ids
def insert_documents(transaction_executor, table_name, documents):
    """
    Insert the given list of documents into a table in a single transaction.

    :type transaction_executor: :py:class:`pyqldb.session.executor.Executor`
    :param transaction_executor: An Executor object allowing for execution of statements within a transaction.

    :type table_name: str
    :param table_name: Name of the table to insert documents into.

    :type documents: list
    :param documents: List of documents to insert.

    :rtype: list
    :return: List of documents IDs for the newly inserted documents.
    """
    logger.info('Inserting some documents in the {} table...'.format(table_name))
    statement = 'INSERT INTO {} ?'.format(table_name)
    cursor = transaction_executor.execute_statement(statement, [convert_object_to_ion(documents)])
    list_of_document_ids = get_document_ids_from_dml_results(cursor)

    return list_of_document_ids
def insert_documents(driver, table_name, documents):
    """
    Insert the given list of documents into a table in a single transaction.

    :type driver: :py:class:`pyqldb.driver.qldb_driver.QldbDriver`
    :param driver: An instance of the QldbDriver class.

    :type table_name: str
    :param table_name: Name of the table to insert documents into.

    :type documents: list
    :param documents: List of documents to insert.

    :rtype: list
    :return: List of documents IDs for the newly inserted documents.
    """
    logger.info(
        'Inserting some documents in the {} table...'.format(table_name))
    statement = 'INSERT INTO {} ?'.format(table_name)
    cursor = driver.execute_lambda(lambda executor: executor.execute_statement(
        statement, convert_object_to_ion(documents)))
    list_of_document_ids = get_document_ids_from_dml_results(cursor)

    return list_of_document_ids