-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcass2.py
37 lines (30 loc) · 839 Bytes
/
cass2.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
from cassandra.cluster import Cluster
cluster = Cluster(['127.0.0.1'])
session = cluster.connect()
# Set the keyspace
session.set_keyspace('employee')
# Create a table
table_query = """
CREATE TABLE IF NOT EXISTS details (
user_id UUID PRIMARY KEY,
username text,
email text,
age int
);
"""
session.execute(table_query)
# Insert data into the table
insert_query = """
INSERT INTO details (user_id, username, email, age) VALUES (
UUID(), 'john_doe', 'john.doe@example.com', 30
);
"""
session.execute(insert_query)
# Query data from the table
select_query = "SELECT * FROM details;"
result = session.execute(select_query)
print("Data in the 'details' table:")
for row in result:
print(row.user_id, row.username, row.email, row.age)
# Close the connection
cluster.shutdown()