Add newsgroup table

This commit is contained in:
XANTRONIX Development 2024-11-08 20:31:00 -05:00
parent 129d3c19ab
commit b52ef29ac3
2 changed files with 19 additions and 7 deletions

View file

@ -1,11 +1,21 @@
begin transaction;
create table newsgroup (
id INTEGER PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL
);
create table newsgroup_message (
id INTEGER PRIMARY KEY NOT NULL,
created_on DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
sender TEXT NOT NULL,
subject TEXT NOT NULL,
content TEXT NOT NULL
id INTEGER PRIMARY KEY NOT NULL,
newsgroup_id INTEGER NOT NULL,
message_id TEXT NOT NULL,
created_on DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
sender TEXT NOT NULL,
subject TEXT NOT NULL,
content TEXT NOT NULL,
FOREIGN KEY(newsgroup_id) REFERENCES newsgroup(id)
);
commit;

View file

@ -8,14 +8,16 @@ class Database():
def __init__(self, path: str):
self.db = sqlite3.connect(path)
def message_add(self, message: Message):
def message_add(self, newsgroup_id: int, message: Message):
sql = """
insert into
newsgroup_message
(created_on, sender, subject, content) values (?, ?, ?, ?)
(newsgroup_id, message_id, created_on, sender, subject, content) values (?, ?, ?, ?, ?, ?)
"""
self.db.execute(sql, (
newsgroup_id,
message.id(),
message.date().isoformat(),
message.sender(),
message.subject(),