@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

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.638946101896354","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZnJvbSBjOCBpbXBvcnQgQzhDbGllbnQKaW1wb3J0IGpzb24KCnByaW50KCJDb25uZWN0aW5nIHRvIE1hY3JvbWV0YSBnbG9iYWwgRmFicmljIC4uLiIpCmNsaWVudCA9IEM4Q2xpZW50KHByb3RvY29sPSdodHRwcycsIGhvc3Q9J3RyeS5tYWNyb21ldGEuaW8nLCBwb3J0PTQ0MykKI0FkZCB5b3VyIHRlbmFudCBkZXRhaWxzLCB1c2VyIGlkIGFuZCBwYXNzd29yZCBiZWxvdwpmYWJyaWMgPSBjbGllbnQuZmFicmljKAogICAgdGVuYW50PSdPdXRLYXN0NjMwJywKICAgIG5hbWU9J19zeXN0ZW0nLAogICAgdXNlcm5hbWU9J3Jvb3QnLAogICAgcGFzc3dvcmQ9J0tsZXZlclBAJCR3b3JkJykKcHJpbnQoIlxuQ29ubmVjdGVkIHRvIE1hY3JvbWV0YSBnbG9iYWwgRmFicmljIC4uLiIpCgpwcmludCgiXG5HZXR0aW5nIGdlbyBmYWJyaWMgZGV0YWlscy4uLiIpCnByaW50KGpzb24uZHVtcHMoZmFicmljLmZhYnJpY3NfZGV0YWlsKCksIGluZGVudD00KSkKCiMgY3JlYXRpbmcgdGhlIGFkZHJlc3MgYm9vayBjb2xsZWN0aW9uICYgYWRkIHNvbWUgY29udGFjdHMgaWYgaXQgZG9lc250IGV4aXN0CmlmIG5vdCBmYWJyaWMuaGFzX2NvbGxlY3Rpb24oJ2FkZHJlc3NlcycpOgogICAgYWRkcmVzc2VzID0gZmFicmljLmNyZWF0ZV9jb2xsZWN0aW9uKCdhZGRyZXNzZXMnKQogICAgc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Rpb24gdHJ1bmNhdGVkIC4uLiIpCgpwcmludCgiQW5kIHdlJ3JlIGRvbmUhIikK"},"asBuffer":null},"loaded":true}}
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!")