def add_a_good(rows_, conn_=None): _conn = db_utils.getconnection(conn_, db='rs') old_rows = [] dd = rows_diff_by_seq(seq(old_rows), seq(rows_), old_rows, rows_, incl=['NAME'], ind=['NAME'], rplc=False, fillback=False) rows = db_utils.db_operate_dict(_conn, goods, dd, pk=['ID']) # get good id stmt = sql.select([sqlite_sequence.c.seq]).\ select_from(sqlite_sequence).\ where(sqlite_sequence.c.name == 'GOODS') row_data = None for row in _conn.execute(stmt): row_data = db_utils.row2dict(row, has_none=True) if conn_ is None: _conn.close() return row_data['seq'] if conn_ is None: _conn.close() return goods_dict
def add_rates(rows_, conn_=None): _conn = db_utils.getconnection(conn_, db='rs') old_rows = read_rate(conn_=_conn) dd = rows_diff_by_seq(seq(old_rows), seq(rows_), old_rows, rows_, incl=['CID','GID', 'RATE', 'REAL'], ind=['CID','GID'], rplc=False, fillback=False) rows = db_utils.db_operate_dict(_conn, rate, dd, pk=['CID','GID']) if conn_ is None: _conn.close() return rows
def add_customers(rows_, conn_=None): _conn = db_utils.getconnection(conn_, db='rs') old_rows = read_customer() dd = rows_diff_by_seq(seq(old_rows), seq(rows_), old_rows, rows_, incl=['NAME'], ind=['NAME'], rplc=False, fillback=False) rows = db_utils.db_operate_dict(_conn, customer, dd, pk=['ID']) # get goods dict cus_dict = get_customers_dict(conn_=_conn) if conn_ is None: _conn.close() return cus_dict
def update_all_pred_rate(rows_, conn_=None): _conn = db_utils.getconnection(conn_, db='rs') stmt = sql.select([rate]).\ select_from(rate).\ where(rate.c.REAL == 0) old_rows = [] for row in _conn.execute(stmt): row_data = db_utils.row2dict(row, has_none=True) old_rows.append(row_data) dd = rows_diff_by_seq(seq(old_rows), seq(rows_), old_rows, rows_, incl=['CID','GID','RATE', 'REAL'], ind=['CID','GID'], rplc=False, fillback=False) rows = db_utils.db_operate_dict(_conn, rate, dd, pk=['CID','GID']) if conn_ is None: _conn.close() return rows
def add_a_customer(rows_, cus_id=None, conn_=None): _conn = db_utils.getconnection(conn_, db='rs') if cus_id: old_rows = read_customer(cus_id=cus_id,conn_=_conn) else: old_rows = [] dd = rows_diff_by_seq(seq(old_rows), seq(rows_), old_rows, rows_, incl=['ID','NAME'], ind=['ID'], rplc=False, fillback=False) rows = db_utils.db_operate_dict(_conn, customer, dd, pk=['ID']) # get cus id stmt = sql.select([sqlite_sequence.c.seq]).\ select_from(sqlite_sequence).\ where(sqlite_sequence.c.name == 'CUSTOMER') row_data = None for row in _conn.execute(stmt): row_data = db_utils.row2dict(row, has_none=True) if conn_ is None: _conn.close() return row_data['seq'] if cus_id == None else cus_id