Testing for SQL Django integration
parent
23c63ee0db
commit
0d98ac8477
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue