async def run(self, ctx: Context): async with ctx.threadpool(): num_rows = 0 with self.csv_path.open() as csvfile: reader = csv.reader(csvfile, delimiter='|') for name, city, phone, email in reader: num_rows += 1 ctx.sql.execute( people.insert().values(name=name, city=city, phone=phone, email=email)) logger.info('Imported %d rows of data', num_rows)
async def run(self, ctx: Context): async with ctx.threadpool(): num_rows = 0 with self.csv_path.open() as csvfile: reader = csv.reader(csvfile, delimiter='|') for name, city, phone, email in reader: num_rows += 1 ctx.sql.add( Person(name=name, city=city, phone=phone, email=email)) # Emit pending INSERTs (though this would happen when the context ends anyway) ctx.sql.flush() logger.info('Imported %d rows of data', num_rows)
async def run(self, ctx: Context, *, dbsession: Session = resource()) -> None: async with ctx.threadpool(): num_rows = 0 with self.csv_path.open() as csvfile: reader = csv.reader(csvfile, delimiter="|") for name, city, phone, email in reader: num_rows += 1 dbsession.execute(people.insert().values(name=name, city=city, phone=phone, email=email)) logger.info("Imported %d rows of data", num_rows)
async def run(self, ctx: Context, *, dbsession: Session = resource()) -> None: async with ctx.threadpool(): num_rows = 0 with self.csv_path.open() as csvfile: reader = csv.reader(csvfile, delimiter="|") for name, city, phone, email in reader: num_rows += 1 dbsession.add( Person(name=name, city=city, phone=phone, email=email)) # Emit pending INSERTs (though this would happen when the context ends # anyway) dbsession.flush() logger.info("Imported %d rows of data", num_rows)