changeset 8:adf056d67c01

ability to export entire db to directory
author Jeff Hammel <k0scist@gmail.com>
date Sat, 01 Apr 2017 13:01:57 -0700
parents 7d6acedf1a67
children 834b920ae345
files sqlex/main.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sqlex/main.py	Sat Apr 01 12:37:38 2017 -0700
+++ b/sqlex/main.py	Sat Apr 01 13:01:57 2017 -0700
@@ -108,7 +108,16 @@
             sys.stdout.flush()
     else:
         # output entire db to CSV files in directory
-        raise NotImplementedError('TODO')
+
+        # ensure directory exists
+        ensure_dir(options.output)
+
+        for table in db.tables():
+            # export each table
+            path = os.path.join(options.output, '{}.csv'.format(table))
+            with open(path, 'w') as f:
+                db.table2csv(table, f)
+
 
 if __name__ == '__main__':
     main()