Skip to content

Commit

Permalink
feat: db creation
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitroPodolsky authored and nezutero committed Feb 19, 2024
1 parent 9de9bbf commit 21f875b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use rusqlite::Connection;

pub fn create_db() {
let conn = Connection::open("your_database.db").expect("Failed to open database");

conn.execute(
"CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT
)",
[],
).expect("Failed to create users table");

conn.execute(
"CREATE TABLE IF NOT EXISTS category (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
)",
[],
).expect("Failed to create category table");

conn.execute(
"CREATE TABLE IF NOT EXISTS homework_hub (
name TEXT PRIMARY KEY,
desc TEXT NOT NULL,
deadline DATE,
date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
category_id INTEGER,
user_id INTEGER,
FOREIGN KEY (category_id) REFERENCES category(id),
FOREIGN KEY (user_id) REFERENCES users(id)
)",
[],
).expect("Failed to create homework_hub table");

log::info!("created database successfully!");
}
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
pub mod bot;
pub mod db;

use db::create_db;
use bot::*;
use teloxide::{dispatching::dialogue::InMemStorage, prelude::*};

#[tokio::main]
async fn main() {
log::info!("Starting dialogue bot...");
create_db();
pretty_env_logger::init();

let bot = Bot::from_env();
Expand Down

0 comments on commit 21f875b

Please sign in to comment.