Add type foundations and structure.
This commit is contained in:
parent
51bbfa1af0
commit
ea93622381
7 changed files with 199 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
98
Cargo.lock
generated
Normal file
98
Cargo.lock
generated
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "calamari"
|
||||||
|
version = "0.0.0-indev"
|
||||||
|
dependencies = [
|
||||||
|
"sqlite",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47"
|
||||||
|
dependencies = [
|
||||||
|
"shlex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.161"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sqlite"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5dfe6fb16f2bee6452feeb4d12bfa404fbcd3cfc121b2950e501d1ae9cae718e"
|
||||||
|
dependencies = [
|
||||||
|
"sqlite3-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sqlite3-src"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "174d4a6df77c27db281fb23de1a6d968f3aaaa4807c2a1afa8056b971f947b4a"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sqlite3-sys"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3901ada7090c3c3584dc92ec7ef1b7091868d13bfe6d7de9f0bcaffee7d0ade5"
|
||||||
|
dependencies = [
|
||||||
|
"sqlite3-src",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uuid"
|
||||||
|
version = "1.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "calamari"
|
||||||
|
version = "0.0.0-indev"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
sqlite = "0.36.1"
|
||||||
|
uuid = { version = "1.11.0", features = ["v4"] }
|
2
src/db/mod.rs
Normal file
2
src/db/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
// Database abstraction.
|
||||||
|
mod sqlite;
|
42
src/db/sqlite.rs
Normal file
42
src/db/sqlite.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
// SQLite to Calamari DB abstraction.
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub struct DatabaseCredentials {
|
||||||
|
pub server: Option<String>,
|
||||||
|
pub username: Option<String>,
|
||||||
|
pub password: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DatabaseCredentials {
|
||||||
|
pub fn new() -> DatabaseCredentials {
|
||||||
|
return DatabaseCredentials { server: None, username: None, password: None };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Database {
|
||||||
|
connection: sqlite::Connection,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub fn open(creds: DatabaseCredentials) -> Result<Database, String> {
|
||||||
|
if creds.server.is_none() {
|
||||||
|
return Err("No database location provided.".to_string());
|
||||||
|
}
|
||||||
|
let conn = sqlite::open(PathBuf::from(creds.server.unwrap()));
|
||||||
|
if conn.is_ok() {
|
||||||
|
return Ok(Database { connection: conn.unwrap() });
|
||||||
|
} else {
|
||||||
|
return Err("Issue opening DB".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_schema(&mut self) -> Result<(), sqlite::Error> {
|
||||||
|
let query = "
|
||||||
|
CREATE TABLE devices (uuid TEXT, current_channel TEXT);
|
||||||
|
CREATE TABLE channels (uuid TEXT, name TEXT, widgets TEXT);
|
||||||
|
CREATE TABLE widgets (uuid TEXT, name TEXT, location TEXT);
|
||||||
|
CREATE TABLE users (uuid TEXT, username TEXT, password TEXT);
|
||||||
|
";
|
||||||
|
return self.connection.execute(query);
|
||||||
|
}
|
||||||
|
}
|
7
src/main.rs
Normal file
7
src/main.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// Calamari server main file.
|
||||||
|
mod schema;
|
||||||
|
mod db;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
}
|
41
src/schema.rs
Normal file
41
src/schema.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// Common Calamari server types used throughout the program.
|
||||||
|
use uuid::Uuid;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Device {
|
||||||
|
pub uuid: Uuid,
|
||||||
|
pub current_channel: Option<Channel>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Device {
|
||||||
|
pub fn new() -> Device {
|
||||||
|
return Device { uuid: Uuid::nil(), current_channel: None };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Channel {
|
||||||
|
pub uuid: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub widgets: Vec<Widget>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Channel {
|
||||||
|
pub fn new() -> Channel {
|
||||||
|
return Channel { uuid: Uuid::nil(), name: "".to_string(), widgets: vec![] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Widget {
|
||||||
|
pub uuid: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub location: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget {
|
||||||
|
pub fn new() -> Widget {
|
||||||
|
return Widget { uuid: Uuid::nil(), name: "".to_string(), location: PathBuf::new() };
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue