-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_quickstart.py
More file actions
30 lines (25 loc) · 875 Bytes
/
python_quickstart.py
File metadata and controls
30 lines (25 loc) · 875 Bytes
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
#!/usr/bin/env python3
"""CuttleDB Python quickstart — assumes server running on 127.0.0.1:7780.
Start the server:
cuttledb-server --port 7780
Run this:
python examples/python_quickstart.py
"""
from cuttledb import CuttleDB, ColType
with CuttleDB.connect("127.0.0.1", 7780) as db:
hid = db.open()
tid = db.create(hid, "txn", [
("customer", ColType.STRING),
("type", ColType.STRING),
("amount", ColType.INT),
])
db.insert_batch(hid, tid, [
["alice", "purchase", 100],
["bob", "purchase", 250],
["alice", "refund", -50],
])
print(f"rows: {db.count(hid, tid)}")
print(f"sum amount: {db.sum(hid, tid, 2)}")
print(f"min amount: {db.min(hid, tid, 2)}")
print(f"max amount: {db.max(hid, tid, 2)}")
print(f"rows > 100: {db.select_gt(hid, tid, 2, 100)}")