Last active
September 5, 2019 19:31
-
-
Save FBosler/c0c7e0ec7682b68c89c0c916ce4d8252 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PSEUDO_DATABASE = { | |
'students': [{ | |
'_id': '1234', | |
'name': 'John Doe', | |
'age': 15 | |
},{ | |
'_id': '1235', | |
'name': 'Jane Dane', | |
'age': 14 | |
}], | |
'class_rooms': [{ | |
'_id': 'abcd', | |
'floor': 10, | |
'seats': 15 | |
},{ | |
'_id': 'xgho', | |
'floor': 8, | |
'seats': 20 | |
}] | |
} | |
def mock_fetch_from_db(table,_id): | |
records = PSEUDO_DATABASE.get(table,{}) | |
for record in records: | |
if _id == record['_id']: | |
return record | |
def mock_upsert_to_db(table,to_upload): | |
records = PSEUDO_DATABASE.get(table,{}) | |
for idx, record in enumerate(records): | |
if to_upload['_id'] == record['_id']: | |
break | |
else: | |
idx = None | |
if not None: | |
records.pop(idx) | |
records.append(to_upload) | |
PSEUDO_DATABASE[table] = records |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment