# -*- coding: utf-8 -*-

import records
import traceback


class DbRecordOpt:
    def __init__(self):

        try:
            self.con = records.Database('mysql+pymysql://root:admin666@172.30.100.253:3306/test_qa')
        except:
            print(traceback.print_exc())
            raise

    def querry_excute(self, order):
        return self.con.query(order).as_dict()

    def write_excute(self, order):
        return self.con.query(order)

    def batch(self, order, param):
        return self.con.bulk_query(order, param)

    def tranc_excute(self, order_list):
        tr = self.con.transaction()
        try:
            for i in order_list:
                self.con.query(i)
            tr.commit()
            return 0
        except:
            tr.rollback()
            return 1
