Skip to content

Commit

Permalink
[sqlite] save list/dict as json #1589
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Oct 18, 2023
1 parent e9c0d94 commit ddd352d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions visidata/loaders/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def iterload(self):
@VisiData.api
def save_sqlite(vd, p, *vsheets):
import sqlite3
import json
jsonenc = json.JSONEncoder() #1589: list/dict values as json

conn = sqlite3.connect(str(p))
conn.text_factory = lambda s, enc=vsheets[0].options.encoding: s.decode(enc)
conn.row_factory = sqlite3.Row
Expand Down Expand Up @@ -256,6 +259,8 @@ def save_sqlite(vd, p, *vsheets):
v = options.safe_error
else:
v = None
elif isinstance(v, (list, tuple, dict)):
v = jsonenc.encode(v)
elif not isinstance(v, (int, float, str)):
v = col.getDisplayValue(r)
sqlvals.append(v)
Expand Down

0 comments on commit ddd352d

Please sign in to comment.