Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Merge f2ca352 into 872f4ec
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Apr 30, 2020
2 parents 872f4ec + f2ca352 commit e2f9ef9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tabulator/writers/sql.py
Expand Up @@ -32,12 +32,19 @@ def __init__(self, table=None, **options):
def write(self, source, target, headers, encoding=None):
engine = create_engine(target)
count = 0
buffer = []
buffer_size = 1000
with engine.begin() as conn:
meta = MetaData()
columns = [Column(header, String()) for header in headers]
table = Table(self.__table, meta, *columns)
meta.create_all(conn)
for row in source:
conn.execute(table.insert(tuple(row)))
count += 1
buffer.append(row)
if len(buffer) > buffer_size:
conn.execute(table.insert().values(buffer))
buffer = []
if len(buffer):
conn.execute(table.insert().values(buffer))
return count

0 comments on commit e2f9ef9

Please sign in to comment.