Assembly separation
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "database/assebmlr"]
|
||||||
|
path = database/assebmlr
|
||||||
|
url = https://git.denco.store/agonex/Assemblr-Database.git
|
||||||
1
database/__init__.py
Normal file
1
database/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from assebmlr.models import *
|
||||||
1
database/assebmlr
Submodule
1
database/assebmlr
Submodule
Submodule database/assebmlr added at 4096f3f868
39
database/mariadb.py
Normal file
39
database/mariadb.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import mariadb
|
||||||
|
import settings
|
||||||
|
|
||||||
|
|
||||||
|
class MariadbConnector:
|
||||||
|
def __init__(self):
|
||||||
|
# Settings
|
||||||
|
self.user = settings.MY_LOGIN
|
||||||
|
self.password = settings.MY_PASSWORD
|
||||||
|
self.host = settings.MY_HOST
|
||||||
|
self.port = int(settings.MY_PORT)
|
||||||
|
self.database = settings.MY_DATABASE
|
||||||
|
|
||||||
|
self.conn = self._get_connection()
|
||||||
|
self.cursor = self._get_cursor()
|
||||||
|
|
||||||
|
def _get_connection(self) -> mariadb.connections.Connection:
|
||||||
|
return mariadb.connect(user=self.user,
|
||||||
|
password=self.password,
|
||||||
|
host=self.host,
|
||||||
|
port=self.port,
|
||||||
|
database=self.database)
|
||||||
|
|
||||||
|
def _get_cursor(self) -> mariadb.cursors.Cursor:
|
||||||
|
return self.conn.cursor()
|
||||||
|
|
||||||
|
def select(self, query_string: str, as_list=True):
|
||||||
|
cursor = self.cursor
|
||||||
|
|
||||||
|
cursor.execute(query_string)
|
||||||
|
if not as_list:
|
||||||
|
return cursor.fetchone()
|
||||||
|
return cursor.fetchall()
|
||||||
|
|
||||||
|
def insert(self, query_string) -> int:
|
||||||
|
cursor = self.cursor
|
||||||
|
|
||||||
|
cursor.execute(query_string)
|
||||||
|
return cursor.insert_id
|
||||||
Reference in New Issue
Block a user