Ejemplo n.º 1
0
    def _send(self, src_message_header, data, **kwargs):
        '''execute insert statement against objectstore DB'''

        rec_data = self.tablespec.convert_data(data)
        rec_data['generation'] = 0
        rec_data['correction_id'] = None
        insert_statement = self._insert_sql.bindparams(**rec_data)

        with sqlx.txn_scope(self.database) as session:
            session.execute(insert_statement)
Ejemplo n.º 2
0
    def insert_test_record(self, record, target_db):

        insert_sql = text('''
        insert into "test"."objects"
        (EVENT_TYPE, EVENT_UUID, PRICE, EVENT_DATE, GENERATION, CORRECTION_ID)
        values
        (:objtype, :uuid, :price, :date, 0, NULL)
        ''')

        insert_stmt = insert_sql.bindparams(date=record['DATE'],
                                            price=record['PRICE'],
                                            objtype=record['TYPE'],
                                            uuid=record['UUID'])
        with sqlx.txn_scope(target_db) as session:
            session.execute(insert_stmt)
Ejemplo n.º 3
0
    def test_tablespec_config_generates_correct_insert_statement(self):
        configfile = 'data/sample_objectstore_cfg.yaml'

        obj_store_cfg = obs.ObjectstoreConfig(configfile)
        self.log.debug(obj_store_cfg.tablespec.sql)

        tblspec = obj_store_cfg.tablespec
        self.create_object_table(tblspec, obj_store_cfg.database)
        self.load_test_data('data/sample_objectstore.csv',
                            obj_store_cfg.database)

        self.log.debug(tblspec.insert_statement_template)

        with sqlx.txn_scope(obj_store_cfg.database) as session:
            drop_statement = 'DROP TABLE "%s"."%s"' % (tblspec.schema,
                                                       tblspec.tablename)
            session.execute(drop_statement)

        self.assertTrue(False)
Ejemplo n.º 4
0
    def test_tablespec_config_loads_valid_tablespec(self):
        configfile = 'data/sample_objectstore_cfg.yaml'

        obj_store_cfg = obs.ObjectstoreConfig(configfile)
        self.log.debug(obj_store_cfg.tablespec.sql)

        tblspec = obj_store_cfg.tablespec
        self.create_object_table(tblspec, obj_store_cfg.database)

        engine = obj_store_cfg.database.get_engine()
        self.assertTrue(
            engine.dialect.has_table(engine,
                                     tblspec.tablename,
                                     schema=tblspec.schema))

        with sqlx.txn_scope(obj_store_cfg.database) as session:
            drop_statement = 'DROP TABLE "%s"."%s"' % (tblspec.schema,
                                                       tblspec.tablename)
            session.execute(drop_statement)
Ejemplo n.º 5
0
 def create_object_table(self, tablespec, db):
     with sqlx.txn_scope(db) as session:
         session.execute(tablespec.sql)
Ejemplo n.º 6
0
 def clear_object_table(self, db):
     with sqlx.txn_scope(db) as session:
         drop_statement = 'TRUNCATE TABLE "%s"."%s"' % (TESTING_SCHEMA,
                                                        OBJECT_TABLE_NAME)
         session.execute(drop_statement)
Ejemplo n.º 7
0
 def destroy_object_table(self, db):
     with sqlx.txn_scope(db) as session:
         drop_statement = 'DROP TABLE "%s"."%s"' % (TESTING_SCHEMA,
                                                    OBJECT_TABLE_NAME)
         session.execute(drop_statement)