Mcfly is the library to query and update the Delorean database in Python.
Mcfly uses the following models to represent Delorean entities:
A catalogue is a "branch" of the delorean database. It is where you store your documents. The catalogue model has the following properties:
name - Corresponds to the name of the catalogue. This is immutable and is a part of the URI for your documents. count - Document count. This number represents how many documents this catalogue currently holds.
A document is a representation of something you stored in the database. The document model has the following properties:
uri - The unique identifier for the document, preceded by the name of the catalogue. id - The unique identified for the document. timestamp - The time of creation of the document. body - The actual dictionary that represents the json that was sent to the database.
Connecting to the database is really simple:
connection = Connection(username='admin', password='12345')
You can also specify the host and port:
connection = Connection(username='admin', password='12345', host='http://mydelorean.myapp.com', port=8888)
Creating a catalogue is used with the create_catalogue command from the connection class:
connection = Connection(username='admin', password='12345') catalogue = connection.my_catalogue #implicitly creates the catalogue
You can also retrieve a catalogue using:
catalogue = connection.my_catalogue
Given you have a catalogue storing a new document in it, is as simple as:
my_message = { 'first-name': 'Bernardo', 'last-name': 'Heynemann } document = connection.my_catalogue.store(my_message)
Getting a document by its id is as simple as:
document = connection.my_catalogue.get('23kr4092')
You can also retrieve all documents from a catalogue (in the order they were inserted), using:
documents = connection.my_catalogue.get_documents()