Testing for SQL Django integration

tyler
tylerklane 2024-03-21 17:52:00 -04:00
parent 23c63ee0db
commit 0d98ac8477
2 changed files with 16 additions and 7 deletions

View File

@ -1,10 +1,14 @@
import uuid
try:
from .config import Database
except ImportError:
from config import Database
from django.db import connection
"""
BOOKS DATABASE ATTRIBUTES
*id: str
@ -17,11 +21,10 @@ BOOKS DATABASE ATTRIBUTES
def createBookTable():
db = Database()
query = "CREATE TABLE books (id varchar(255) NOT NULL PRIMARY KEY, title varchar(255), size varchar(255), status varchar(255), numImages int, coverExt varchar(255));"
db.sendQuery(query)
db.commit()
db.close()
with connection.cursor() as cursor:
cursor.execute(query)
return cursor.fetchall()
def jsonifyBook(book: tuple):

View File

@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@ -75,9 +77,13 @@ WSGI_APPLICATION = "alttextbackend.wsgi.application"
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ['DATABASE_NAME'],
'USER': os.environ['DATABASE_USER'],
'PASSWORD': os.environ['DATABASE_PASSWORD'],
'HOST': os.environ['DATABASE_HOST'], # Or the address of your database server
'PORT': os.environ['DATABASE_PORT'], # Default PostgreSQL port
}
}