我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用sqlalchemy.types.NVARCHAR。
def insert_db(data, table_name, write_index, primary_keys): # ??engine engine_mysql = engine() # ?? http://docs.sqlalchemy.org/en/latest/core/reflection.html # ???????????????? insp = inspect(engine_mysql) col_name_list = data.columns.tolist() # ????????????varchar??? if write_index: # ????????? col_name_list.insert(0, data.index.name) print(col_name_list) data.to_sql(name=table_name, con=engine_mysql, schema=MYSQL_DB, if_exists='append', dtype={col_name: NVARCHAR(length=255) for col_name in col_name_list}, index=write_index) # ???????? if insp.get_primary_keys(table_name) == []: with engine_mysql.connect() as con: # ?????????? try: con.execute('ALTER TABLE `%s` ADD PRIMARY KEY (%s);' % (table_name, primary_keys)) except Exception as e: print("################## ADD PRIMARY KEY ERROR :", e) # ?????