File size: 1,426 Bytes
cdfb101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11b1f01
c84c366
cdfb101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
import os
from dotenv import load_dotenv
import psycopg2
import mysql.connector as sql

load_dotenv()

class DB:
    def __init__(self):
        self.string = os.getenv("Connection_String")
        self.collection = os.getenv("Collection_Name")
        self.host = os.getenv("Host")
        self.port = os.getenv("Port")
        self.user = os.getenv("User")
        self.password = os.getenv("Password")
        self.db = os.getenv("DB_Name")
    
    def connect_PS(self):
        self.connection_PS = psycopg2.connect(self.string)
        self.cursor_PS = self.connection_PS.cursor()
    
    def connect_MS(self):
        self.connection_MS = sql.connect(
            host = self.host,
            port = self.port,
            user = self.user,
            password = self.password,
            database = self.db
        )
        self.cursor_MS = self.connection_MS.cursor()

    def insert(self, data):
        insert_query = "INSERT INTO user(n,email_id,d,t,pasword,score) VALUES (%s,%s,%s,%s,%s,%s)"
        self.cursor_MS.execute(insert_query, data)


    def clear(self):
        self.cursor_PS.execute(f"DELETE FROM {self.collection}")
        self.connection_PS.commit()
    
    def close_PS(self):
        self.cursor_PS.close()
        self.connection_PS.close()
    
    def close_MS(self):
        self.cursor_MS.close()
        self.connection_MS.close()