Skip to content

Instantly share code, notes, and snippets.

@cassioeskelsen
Last active June 12, 2021 15:28
Show Gist options
  • Select an option

  • Save cassioeskelsen/fe47ee004a66f0803a6b1683db343718 to your computer and use it in GitHub Desktop.

Select an option

Save cassioeskelsen/fe47ee004a66f0803a6b1683db343718 to your computer and use it in GitHub Desktop.
def get_customer(key, value):
if not value:
return None
elif key == "state":
return State(**value)
elif key == "address" and not isinstance(value, str):
return Address(**value)
if __name__ == "__main__":
store = document_store.DocumentStore(urls=['http://localhost:8080'], database="python")
store.conventions.mappers.update({Customer: get_customer})
store.initialize()
customer = create_instance()
with store.open_session() as session:
session.store(customer)
session.save_changes()
with store.open_session() as session:
c = session.load(customer.Id, Customer)
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment