backend: database and file upload test
This commit is contained in:
parent
b62f6d87c7
commit
d786d7f7af
6 changed files with 198 additions and 34 deletions
78
backend/db.py
Normal file
78
backend/db.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
import sqlite3
|
||||
|
||||
class VNDB:
|
||||
|
||||
def __init__(self, db_name='vn_database.db'):
|
||||
self.__db_name = db_name
|
||||
connection = sqlite3.connect(self.__db_name)
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS marks (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
tag TEXT NOT NULL,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS authors (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
thumbnail TEXT NOT NULL
|
||||
);
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS novels (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
author INTEGER NOT NULL
|
||||
);
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS posts_log (
|
||||
|
||||
novel INTEGER NOT NULL,
|
||||
|
||||
channel INTEGER NOT NULL,
|
||||
|
||||
marks JSON NOT NULL,
|
||||
|
||||
title TEXT NOT NULL,
|
||||
|
||||
description TEXT NOT NULL,
|
||||
|
||||
author INTEGER NOT NULL,
|
||||
|
||||
files_on_disk JSON NOT NULL,
|
||||
post_info JSON,
|
||||
post_at INTEGER NOT NULL,
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
''')
|
||||
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def __execute(self, sql: str, params: tuple):
|
||||
connection = sqlite3.connect(self.__db_name)
|
||||
connection.cursor().execute(sql, params)
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def insert_mark(self, type: str, value: str):
|
||||
self.__execute("INSERT INTO marks (tag, value) "
|
||||
"VALUES (?, ?)", (type, value))
|
||||
|
||||
def insert_novel(self, title: str, author_id: int):
|
||||
self.__execute("INSERT INTO novels (title, author) "
|
||||
"VALUES (?, ?)", (title, author_id))
|
||||
|
||||
def insert_author(self, title: str, desc: str, thumb: str):
|
||||
self.__execute("INSERT INTO authors (title, description, thumbnail) "
|
||||
"VALUES (?, ?, ?)", (title, desc, thumb))
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue