-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add db_logger.py and db.py files for database logging and inte…
…rface
- Loading branch information
Showing
11 changed files
with
101 additions
and
1,443 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import certifi | ||
import logging | ||
from dotenv import load_dotenv | ||
from db_logger import bcolors | ||
import datetime | ||
|
||
# Database interface | ||
from pymongo.mongo_client import MongoClient | ||
from pymongo.server_api import ServerApi | ||
from bson.objectid import ObjectId | ||
|
||
load_dotenv() | ||
|
||
|
||
class DatabaseInterface: | ||
def __init__(self): | ||
uri = os.getenv("DB_URI") | ||
self.client = MongoClient( | ||
uri, server_api=ServerApi("1"), tlsCAFile=certifi.where() | ||
) | ||
self.db = self.client.get_database("atlas_main") | ||
self.logger = logging.getLogger(__name__) | ||
print(f"{bcolors.OKGREEN}Database interface initialized{bcolors.ENDC}") | ||
|
||
def get_collection_names(self): | ||
return self.db.list_collection_names() | ||
|
||
def create_collection(self, collection_name): | ||
return self.db.create_collection(collection_name) | ||
|
||
def drop_collection(self, collection_name): | ||
return self.db.drop_collection(collection_name) | ||
|
||
def insert_one(self, collection_name, data): | ||
collection = self.db[collection_name] | ||
return collection.insert_one(data) | ||
|
||
def insert_many(self, collection_name, data): | ||
collection = self.db[collection_name] | ||
return collection.insert_many(data) | ||
|
||
|
||
if __name__ == "__main__": | ||
db_interface = DatabaseInterface() | ||
|
||
document_parent = { | ||
"prompt_id": ObjectId(), | ||
"feature_path": "experiments.conditions.name", | ||
"github_url": "server/features/experiments/conditions/name.py", | ||
"versions": [ | ||
{ | ||
"performace": 0.2, | ||
"average_cost": 0.3, | ||
"commit_SHA": "1234567890", | ||
"created_at": datetime.datetime.now(), | ||
} | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class bcolors: | ||
HEADER = "\033[95m" | ||
OKBLUE = "\033[94m" | ||
OKCYAN = "\033[96m" | ||
OKGREEN = "\033[92m" | ||
WARNING = "\033[93m" | ||
FAIL = "\033[91m" | ||
ENDC = "\033[0m" | ||
BOLD = "\033[1m" | ||
UNDERLINE = "\033[4m" |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.