refactored some code, started creating groups

This commit is contained in:
GitProtogen
2026-03-07 11:32:17 +01:00
parent 51a94fea19
commit 09523a5509
4 changed files with 67 additions and 18 deletions
+14 -4
View File
@@ -21,16 +21,26 @@ class Handler
{
$this->pdo = new PDO('sqlite:' . __DIR__ . '/../../storage/database.sqlite');
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function init(): void
{
$this->pdo->exec("
CREATE TABLE IF NOT EXISTS users (
username VARCHAR(32) NOT NULL UNIQUE,
password CHAR(255) NOT NULL
)
");
$this->pdo->exec("
CREATE TABLE IF NOT EXISTS chat_groups (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(64) NOT NULL UNIQUE
)
");
$this->pdo->exec("
CREATE TABLE IF NOT EXISTS group_members (
group_id INTEGER NOT NULL,
username VARCHAR(32) NOT NULL,
PRIMARY KEY (group_id, username),
FOREIGN KEY (username) REFERENCES users(username)
)
");
}
public function addUser(string $username, string $password): void