@@ -97,6 +97,7 @@ def flatten(
9797 gzip_input = False ,
9898 json_path = "" ,
9999 arrays_new_table = False ,
100+ truncate = False ,
100101):
101102 global LOGGING_SETUP
102103 if not LOGGING_SETUP :
@@ -144,7 +145,8 @@ def flatten(
144145 table_prefix , id_prefix , emit_obj , force ,
145146 schema , schema_titles , path , json_stream , ndjson ,
146147 sqlite_path , threads , log_error , postgres , postgres_schema ,
147- drop , pushdown , sql_scripts , evolve , no_link , stats , low_disk , low_memory , gzip_input , json_path , arrays_new_table )
148+ drop , pushdown , sql_scripts , evolve , no_link , stats , low_disk , low_memory ,
149+ gzip_input , json_path , arrays_new_table , truncate )
148150 elif method == 'iter' :
149151 if path :
150152 raise AttributeError ("path not allowed when supplying an iterator" )
@@ -157,7 +159,7 @@ def flatten(
157159 table_prefix , id_prefix , emit_obj , force ,
158160 schema , schema_titles , sqlite_path , threads , log_error ,
159161 postgres , postgres_schema , drop , pushdown , sql_scripts , evolve ,
160- no_link , stats , low_disk , low_memory , gzip_input , json_path , arrays_new_table )
162+ no_link , stats , low_disk , low_memory , gzip_input , json_path , arrays_new_table , truncate )
161163 else :
162164 raise AttributeError ("input needs to be a string or a generator of strings, dicts or bytes" )
163165
@@ -241,6 +243,7 @@ def iterator_flatten(*args, **kw):
241243@click .option ('--postgres-schema' , default = "" , help = 'When loading to postgres, put all tables into this schema.' )
242244@click .option ('--evolve' , is_flag = True , default = False , help = 'When loading to postgres or sqlite, evolve tables to fit data' )
243245@click .option ('--drop' , is_flag = True , default = False , help = 'When loading to postgres or sqlite, drop table if already exists.' )
246+ @click .option ('--truncate' , is_flag = True , default = False , help = 'When loading to postgres or sqlite, truncate the table if it alraedy exists.' )
244247@click .option ('--id-prefix' , default = "" , help = 'Prefix for all `_link` id fields' )
245248@click .option ('--stats' , is_flag = True , default = False , help = 'Produce stats about the data in the datapackage.json file' )
246249@click .argument ('inputs' , required = False , nargs = - 1 )
@@ -280,6 +283,7 @@ def cli(
280283 stats = False ,
281284 json_path = "" ,
282285 arrays_new_table = False ,
286+ truncate = False
283287):
284288 if web :
285289 import pathlib
@@ -347,6 +351,7 @@ def cli(
347351 stats = stats ,
348352 json_path = json_path ,
349353 arrays_new_table = arrays_new_table ,
354+ truncate = truncate ,
350355 )
351356 except IOError :
352357 pass
0 commit comments