def create_handler(oci_config, log_handler): """Create the handle used to perform OCI NoSQL operations on tables. """ sigprov = SignatureProvider(tenant_id=oci_config['tenancy'], user_id=oci_config['user'], private_key=oci_config['key_file'], fingerprint=oci_config['fingerprint']) nosql_handle_config = NoSQLHandleConfig(Regions.SA_SAOPAULO_1) nosql_handle_config.set_authorization_provider(sigprov) nosql_handle_config.set_default_compartment(oci_config['compartment']) nosql_handle_config.set_logger(log_handler) nosql_handle = NoSQLHandle(nosql_handle_config) sigprov.close() return nosql_handle
def handler(ctx, data: io.BytesIO = None): return_citizens = [] try: provider = SignatureProvider( tenant_id='Your Tenant OCID', user_id='Your User OCID', private_key='location of Pem file', fingerprint='The fingerprint for your key pair goes here', pass_phrase='The pass phrase for your key goes here') compartment = 'Your Compartment Name Goes Here' config = NoSQLHandleConfig(Regions.US_ASHBURN_1, provider) config.set_default_compartment(compartment) logger = logging.getLogger('Citizens') logger.setLevel(logging.WARNING) config.set_logger(logger) handle = NoSQLHandle(config) table_name = 'Citizens' ## Prepare select statement# statement = 'select * from ' + table_name request = PrepareRequest().set_statement(statement) prepared_result = handle.prepare(request) ## Query, using the prepared statement# request = QueryRequest().set_prepared_statement(prepared_result) while True: result = handle.query(request) for r in result.get_results(): return_citizens.append(dict(r)) if request.is_done(): break except (Exception, ValueError) as ex: logging.getLogger().info('error parsing json payload: ' + str(ex)) logging.getLogger().info("Inside OCI function") return response.Response(ctx, response_data=json.dumps(return_citizens), headers={"Content-Type": "application/json"})
# https://blogs.oracle.com/lad-cloud-experts/pt/introducao-ao-oracle-nosql-database-cloud-parte-2 # --------------------------------------------------------------------------- from borneo.iam import SignatureProvider from borneo import NoSQLHandleConfig, NoSQLHandle, Regions from borneo import Consistency, QueryRequest # create and close AuthorizationProvider at_provider = SignatureProvider(config_file='~/.oci/config') at_provider.close() # create handle config using a desired region as endpoint and set a # default compartment. handle_config = NoSQLHandleConfig(Regions.SA_SAOPAULO_1) handle_config.set_authorization_provider(at_provider) handle_config.set_default_compartment('<your-compartment-id>') # create the handle. nosql_handle = NoSQLHandle(handle_config) query = """ SELECT propriedades, valor, frete_gratis FROM produtos """ query_request = QueryRequest() # set ABSOLUTE consistency for read requests. query_request.set_consistency(Consistency.ABSOLUTE)