When my flask application starts up, it needs to add a bunch of data to Postgres via SQLalchemy. I'm looking for a good way to do this. The data is in TSV format, and I already have a SQLalchemy db.model schema for it. Right now:
for datafile in datafiles:
with open(datafile,'rb') as file:
# reader = csv.reader(file, delimiter='\t')
reader = csv.DictReader(file, delimiter='\t', fieldnames=[])
OCRs = # somehow efficiently convert to list of dicts...
db.engine.execute(OpenChromatinRegion.__table__.insert(), OCRs)
Is there a better, more direct way? Otherwise, what is the best way of generating OCRs
?
The solution suggested here seems clunky.