Skip to content

Commit 64d12d6

Browse files
committed
✨ add function to convert JSONB blobs to textual JSON in SQLite
1 parent 1847200 commit 64d12d6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/sqlite3_to_mysql/sqlite_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ def check_sqlite_table_xinfo_support(version_string: str) -> bool:
5353
"""Check for SQLite table_xinfo support."""
5454
sqlite_version: Version = version.parse(version_string)
5555
return sqlite_version.major > 3 or (sqlite_version.major == 3 and sqlite_version.minor >= 26)
56+
57+
58+
def sqlite_jsonb_column_expression(quoted_column_name: str) -> str:
59+
"""Return a SELECT expression that converts JSONB blobs to textual JSON while preserving NULLs."""
60+
return 'CASE WHEN "{name}" IS NULL THEN NULL ELSE json("{name}") END AS "{name}"'.format(name=quoted_column_name)

0 commit comments

Comments
 (0)