mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-07-25 15:29:50 +03:00
Finished Release v0.8.2
This commit is contained in:
commit
8f825bc537
|
@ -1,6 +1,10 @@
|
|||
Change Log
|
||||
==========
|
||||
|
||||
v0.8.2
|
||||
------
|
||||
- Fix broken Python 3 support (M1hacka)
|
||||
|
||||
v0.8.1
|
||||
------
|
||||
- Add support for ReplacingMergeTree (leenr)
|
||||
|
|
|
@ -49,6 +49,9 @@ eggs = ${project:name}
|
|||
enum34
|
||||
infi.unittest
|
||||
infi.traceback
|
||||
memory_profiler
|
||||
profilehooks
|
||||
psutil
|
||||
zc.buildout
|
||||
scripts = ipython
|
||||
nosetests
|
||||
|
|
|
@ -50,35 +50,35 @@ class Database(object):
|
|||
|
||||
def insert(self, model_instances, batch_size=1000):
|
||||
from six import next
|
||||
from cStringIO import StringIO
|
||||
from io import BytesIO
|
||||
i = iter(model_instances)
|
||||
try:
|
||||
first_instance = next(i)
|
||||
except StopIteration:
|
||||
return # model_instances is empty
|
||||
return # model_instances is empty
|
||||
model_class = first_instance.__class__
|
||||
|
||||
if first_instance.readonly:
|
||||
raise DatabaseException("You can't insert into read only table")
|
||||
|
||||
def gen():
|
||||
buf = StringIO()
|
||||
buf = BytesIO()
|
||||
buf.write(self._substitute('INSERT INTO $table FORMAT TabSeparated\n', model_class).encode('utf-8'))
|
||||
first_instance.set_database(self)
|
||||
buf.write(first_instance.to_tsv(include_readonly=False).encode('utf-8'))
|
||||
buf.write('\n')
|
||||
buf.write('\n'.encode('utf-8'))
|
||||
# Collect lines in batches of batch_size
|
||||
lines = 2
|
||||
for instance in i:
|
||||
instance.set_database(self)
|
||||
buf.write(instance.to_tsv(include_readonly=False).encode('utf-8'))
|
||||
buf.write('\n')
|
||||
buf.write('\n'.encode('utf-8'))
|
||||
lines += 1
|
||||
if lines >= batch_size:
|
||||
# Return the current batch of lines
|
||||
yield buf.getvalue()
|
||||
# Start a new batch
|
||||
buf = StringIO()
|
||||
buf = BytesIO()
|
||||
lines = 0
|
||||
# Return any remaining lines in partial batch
|
||||
if lines:
|
||||
|
|
Loading…
Reference in New Issue
Block a user