Browse Source

Initialing the Store

main
Julio Biason 2 years ago
parent
commit
7c292a4800
  1. 2
      .gitignore
  2. 2
      Cargo.toml
  3. 6
      store/Cargo.toml
  4. 23
      store/migrations/202212051652_initial.sql
  5. 2
      store/src/domain/mod.rs
  6. 15
      store/src/domain/options.rs
  7. 1
      store/src/lib.rs
  8. 24
      store/src/main.rs

2
.gitignore vendored

@ -14,3 +14,5 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# This we generate in this project
*.sqlite

2
Cargo.toml

@ -2,5 +2,5 @@
members = [
"common",
"core",
"store",
]

6
store/Cargo.toml

@ -2,7 +2,13 @@
name = "store"
version = "0.1.0"
edition = "2021"
authors = ["Julio Biason <julio.biason@pm.me>", ]
description = "Memoirs storage server"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.0.29", features = ["env", "derive", "color"] }
dotenv = "0.15.0"
sqlx = { version = "0.6.2", features = ["sqlite", "uuid", "chrono", "migrate", "runtime-tokio-rustls"] }
tokio = { version = "1.22.0", features = ["macros", "rt"] }

23
store/migrations/202212051652_initial.sql

@ -0,0 +1,23 @@
CREATE TABLE IF NOT EXISTS entry (
id TEXT PRIMARY KEY,
title TEXT,
content TEXT,
source TEXT
);
CREATE TABLE IF NOT EXISTS meta (
id TEXT PRIMARY KEY,
entry TEXT REFERENCES entry (id)
ON DELETE CASCADE,
name VARCHAR(255),
value VARCHAR(255)
);
CREATE TABLE IF NOT EXISTS attachment (
id TEXT PRIMARY KEY,
entry TEXT REFERENCES entry (id)
ON DELETE CASCADE,
name VARCHAR(100),
content_type VARCHAR(100),
content TEXT
);

2
store/src/domain/mod.rs

@ -1 +1,3 @@
//! Store own domain.
pub mod options;

15
store/src/domain/options.rs

@ -0,0 +1,15 @@
//! Options for running the Store server.
use std::path::PathBuf;
use clap::Parser;
#[derive(Parser)]
#[command(author, version, long_about, color = clap::ColorChoice::Always)]
/// Store is the central part of the Memoirs. It keeps all the data from
/// the several Capturers and offers searches for the Viewers.
pub struct Options {
/// Working directory
#[arg(short, long, env = "STORE_PATH", default_value = "./")]
pub working_directory: PathBuf,
}

1
store/src/lib.rs

@ -1 +0,0 @@
mod domain;

24
store/src/main.rs

@ -0,0 +1,24 @@
use clap::Parser;
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::SqlitePoolOptions;
use crate::domain::options::Options;
mod domain;
#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
dotenv::dotenv().ok();
let options = Options::parse();
let pool = SqlitePoolOptions::new()
.connect_with(
SqliteConnectOptions::new()
.filename(options.working_directory.join("memoirs.sqlite"))
.create_if_missing(true),
)
.await?;
sqlx::migrate!("./migrations").run(&pool).await?;
print!("Hello world!");
Ok(())
}
Loading…
Cancel
Save