mod columns;
mod tables;
use crate::database::introspection::{Enum, Schema, Table};
pub(super) use columns::required;
pub(super) use tables::products;
pub(super) fn from_tables(tables: Vec<Table>) -> Schema {
Schema {
tables,
enums: Vec::new(),
}
}
pub(super) fn with_enums(tables: Vec<Table>, enums: Vec<Enum>) -> Schema {
Schema { tables, enums }
}
pub(super) fn enum_type(name: &str, values: &[&str]) -> Enum {
Enum {
name: name.to_string(),
values: values.iter().map(|value| value.to_string()).collect(),
}
}
pub(super) fn schema() -> Schema {
from_tables(vec![products()])
}
pub(super) fn scratch(label: &str) -> std::path::PathBuf {
use std::sync::atomic::{AtomicU32, Ordering};
static COUNTER: AtomicU32 = AtomicU32::new(0);
let path = std::env::temp_dir().join(format!(
"rustyroad-rust-model-test-{label}-{}-{}",
std::process::id(),
COUNTER.fetch_add(1, Ordering::Relaxed)
));
let _ = std::fs::remove_dir_all(&path);
std::fs::create_dir_all(&path).expect("failed to create scratch directory");
path
}