Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safer records #118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mysql_example/mysql_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@


def record_pairs(result_set):
def safe(d):
return {
k: None if v is None or (type(v) == str and len(v) == 0) else v
for (k, v) in d.items()
}

for i, row in enumerate(result_set):
a_record_id, a_record, b_record_id, b_record = row
record_a = (a_record_id, json.loads(a_record))
record_b = (b_record_id, json.loads(b_record))
record_a = (a_record_id, safe(json.loads(a_record)))
record_b = (b_record_id, safe(json.loads(b_record)))

yield record_a, record_b

Expand Down