-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
28 lines (22 loc) · 663 Bytes
/
db.py
File metadata and controls
28 lines (22 loc) · 663 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
from astrapy import DataAPIClient
from dotenv import load_dotenv
import streamlit as st
import os
load_dotenv()
ENDPOINT = os.getenv("ASTRA_ENDPOINT")
TOKEN = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
# connecting to astra db
def get_db():
client = DataAPIClient(TOKEN)
db = client.get_database_by_api_endpoint(ENDPOINT)
return db
db = get_db()
collection_names = ["personal_data", "notes"]
# creating collections in the db
for collection in collection_names:
try:
db.create_collection(collection)
except:
pass
personal_data_collection = db.get_collection("personal_data")
notes_collection = db.get_collection("notes")