command_vault/db/models.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
//! Database models for command-vault
//!
//! This module defines the core data structures used throughout the application.
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
/// Represents a command with its metadata.
///
/// A command includes the actual command string, execution directory,
/// timestamp, tags, and parameters.
///
/// # Example
/// ```rust
/// use command_vault::db::models::Command;
/// use chrono::Utc;
///
/// let cmd = Command {
/// id: None,
/// command: "git push origin main".to_string(),
/// timestamp: Utc::now(),
/// directory: "/project".to_string(),
/// tags: vec!["git".to_string()],
/// parameters: vec![],
/// };
/// ```
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Command {
/// Unique identifier for the command
pub id: Option<i64>,
/// The actual command string
pub command: String,
/// When the command was created or last modified
pub timestamp: DateTime<Utc>,
/// Directory where the command should be executed
pub directory: String,
/// Tags associated with the command
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub tags: Vec<String>,
/// Parameters that can be substituted in the command
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub parameters: Vec<Parameter>,
}
/// Represents a parameter that can be substituted in a command.
///
/// Parameters allow commands to be more flexible by providing
/// placeholders that can be filled in at runtime.
///
/// # Example
/// ```rust
/// use command_vault::db::models::Parameter;
///
/// let param = Parameter {
/// name: "branch".to_string(),
/// description: Some("Git branch name".to_string()),
/// };
/// ```
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Parameter {
/// Name of the parameter (used in substitution)
pub name: String,
/// Optional description of what the parameter does
pub description: Option<String>,
}
impl Parameter {
pub fn new(name: String) -> Self {
Self {
name,
description: None,
}
}
pub fn with_description(name: String, description: Option<String>) -> Self {
Self {
name,
description,
}
}
}