-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_usage.py
More file actions
39 lines (29 loc) · 1.18 KB
/
basic_usage.py
File metadata and controls
39 lines (29 loc) · 1.18 KB
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
from contiguity.base import Base
# Create a Base instance.
db = Base("my-base")
# Put an item with a specific key.
put_result = db.put({"key": "foo", "value": "Hello world!"})
print("Put result:", put_result)
# Put multiple items.
put_result = db.put({"key": "bar", "value": "Bar"}, {"key": "baz", "value": "Baz"})
print("Put many result:", put_result)
# Insert an item with a specific key.
insert_result = db.insert({"key": "john-doe", "name": "John Doe", "age": 30})
print("Insert result:", insert_result)
# Insert an item with a specific key that expires in 1 hour.
expiring_insert_result = db.insert({"key": "jane-doe", "name": "Jane Doe", "age": 28}, expire_in=3600)
print("Insert with expiry result:", expiring_insert_result)
# Get an item using a key.
get_result = db.get("foo")
print("Get result:", get_result)
# Update an item.
update_result = db.update({"age": db.util.increment(2), "name": "Mr. Doe"}, key="john-doe")
print("Update result:", update_result)
# Query items.
query_result = db.query({"age?gt": 25}, limit=10)
print("Query result:", query_result)
# Delete an item.
db.delete("jane-doe-py")
# Delete all items.
for item in db.query().items:
db.delete(str(item["key"]))