Initial commit

This commit is contained in:
2026-10-06 08:24:08 +03:00
commit eb1fd6e2ff
19 changed files with 2112 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
use std::path::Path;
use tokio_rusqlite::{Connection, rusqlite};
pub struct Writer {
// Note that I don't need to wrap this in a mutex because
// tokio_rusqlite already serializes each request into a single executor
pub connection: Connection,
}
impl Writer {
pub async fn new(path: &Path) -> Result<Self, tokio_rusqlite::Error> {
let connection = Connection::open(path).await?;
connection.call(|conn| -> rusqlite::Result<()> {
conn.execute("create table if not exists users (id primary key, username not null, secret not null, unique(username))", [])?;
conn.execute("create table if not exists progress (user_id not null, document_id not null, progress not null, percentage not null, device not null, device_id, timestamp not null, unique(user_id, document_id), foreign key (user_id) references users(id))", [])?;
Ok(())
}).await?;
Ok(Self{connection})
}
}