@ChetanVenkatesh/

Programming Macrometa Global geo distributed DB in Python

Python

Macrometa offers a DB that runs distributed across 25 global data center locations. This repo has python code examples for Macrometa

fork
loading
Files
  • main.py
  • readme.txt
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from c8 import C8Client
import json

print("Connecting to Macrometa global Fabric ...")
client = C8Client(protocol='https', host='try.macrometa.io', port=443)
#Add your tenant details, user id and password below
fabric = client.fabric(
    tenant='OutKast630',
    name='_system',
    username='root',
    password='[email protected]$$word')
print("\nConnected to Macrometa global Fabric ...")

print("\nGetting geo fabric details...")
print(json.dumps(fabric.fabrics_detail(), indent=4))

# creating the address book collection & add some contacts if it doesnt exist
if not fabric.has_collection('addresses'):
    addresses = fabric.create_collection('addresses')
    print("\n\nCreated addresses collection...")

else:
    print("\n\naddresses collection exists")
    addresses = fabric.collection('addresses')

    print("\n\n Inserting contacts into addresses")
cursor = fabric.c8ql.execute(
    'FOR persons IN [ { firstname: "Joseph", lastname: "Smith", email: "[email protected]" },{ firstname: "Astrid", lastname: "Young", email: "[email protected]" },{ firstname: "Boris", lastname: "Balastikov", email: "[email protected]" },{ firstname: "Sherlock", lastname: "Jones", email: "[email protected]" },{ firstname: "Alpha", lastname: "Simpson", email: "[email protected]" },{ firstname: "Jose", lastname: "Garcia", email: "[email protected]" },{ firstname: "Lee", lastname: "Ki", email: "[email protected]" },{ firstname: "Mark", lastname: "Goldfine", email: "[email protected]" },{ firstname: "Ramesh", lastname: "Sriram", email: "[email protected]" }] INSERT persons INTO addresses'
)
docs = [document for document in cursor]
print("\n\nInserted some contact data...")

#Run a query using the built in query language C8QL
print("\n\nExecuting C8QL to retrieve all contacts...")
cursor = fabric.c8ql.execute('FOR contact IN addresses RETURN contact')
docs = [document for document in cursor]
print(json.dumps((docs), indent=4))

#Truncate the collection so that we leave it all cleaned up for the next person
print("\n\nTruncating collection to zero docs ...")
addresses.truncate()
cursor = fabric.c8ql.execute('FOR contact IN addresses RETURN contact')
docs = [document for document in cursor]
print(json.dumps((docs), indent=4))
print("\nCollection truncated ...")

print("And we're done!")