Skip to content

Commit

Permalink
add stubs for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmicu committed Nov 26, 2023
1 parent 0bd3ad3 commit c20bca7
Showing 1 changed file with 192 additions and 0 deletions.
192 changes: 192 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,198 @@ lazy_static! {
pub type SerdeMap = serde_json::Map<String, SerdeValue>;
pub type ValveRow = serde_json::Map<String, SerdeValue>;

pub struct Valve {
global_config: SerdeMap,
compiled_datatype_conditions: HashMap<String, CompiledCondition>,
compiled_rule_conditions: HashMap<String, HashMap<String, Vec<ColumnRule>>>,
pool: AnyPool,
user: String,
}

impl Valve {
/// Given a path to a table table,
/// read it, configure VALVE, and return a new Valve struct.
/// Return an error if reading or configuration fails.
pub fn build(mut self, table_path: &str) -> Result<Self, sqlx::Error> {
// Should be ConfigError
todo!();
Ok(self)
}

/// Set the user name for this instance.
/// The username must be a short string without newlines.
/// Return an error on invalid username.
pub fn set_user(mut self, user: &str) -> Result<Self, sqlx::Error> {
// ConfigError
todo!();
Ok(self)
}

/// Given a database connection string,
/// create a database connection for VALVE to use.
/// Drop and replace any current database connection.
/// Return an error if the connection cannot be created.
pub fn connect(mut self, connection: &str) -> Result<Self, sqlx::Error> {
// DatabaseError
todo!();
Ok(self)
}

/// Create all configured database tables and views
/// if they do not already exist as configured.
/// Return an error on database problems.
pub fn create_all_tables(mut self) -> Result<Self, sqlx::Error> {
// DatabaseError
todo!();
Ok(self)
}

/// Drop all configured tables, in reverse dependency order.
/// Return an error on database problem.
pub fn drop_all_tables(self) -> Result<Self, sqlx::Error> {
// DatabaseError
todo!();
Ok(self)
}

/// Given a vector of table names,
/// drop those tables, in the given order.
/// Return an error on invalid table name or database problem.
pub fn drop_tables(self, tables: Vec<&str>) -> Result<Self, sqlx::Error> {
// DatabaseError
todo!();
Ok(self)
}

/// Truncate all configured tables, in reverse dependency order.
/// Return an error on database problem.
pub fn truncate_all_tables(self) -> Result<Self, sqlx::Error> {
// DatabaseError
todo!();
Ok(self)
}

/// Given a vector of table names,
/// truncate those tables, in the given order.
/// Return an error on invalid table name or database problem.
pub fn truncate_tables(self, tables: Vec<&str>) -> Result<Self, sqlx::Error> {
// ConfigOrDatabaseError
//self.create_all_tables();
todo!();
Ok(self)
}

/// Load all configured tables in dependency order.
/// If `validate` is false, just try to insert all rows.
/// Return an error on database problem,
/// including database conflicts that prevent rows being inserted.
pub fn load_all_tables(self, validate: bool) -> Result<Self, sqlx::Error> {
// DatabaseError
//self.create_all_tables();
//self.truncate_all_tables();
todo!();
Ok(self)
}

/// Given a vector of table names,
/// load those tables in the given order.
/// If `validate` is false, just try to insert all rows.
/// Return an error on invalid table name or database problem.
pub fn load_tables(self, tables: Vec<&str>, validate: bool) -> Result<Self, sqlx::Error> {
// ConfigOrDatabaseError
//self.create_all_tables();
//self.truncate_tables(tables);
todo!();
Ok(self)
}

/// Save all configured tables to their 'path's.
/// Return an error on writing or database problem.
pub fn save_all_tables(self) -> Result<Self, sqlx::Error> {
// WriteOrDatabaseError
todo!();
Ok(self)
}

/// Given a vector of table names,
/// Save thosee tables to their 'path's, in the given order.
/// Return an error on writing or database problem.
pub fn save_tables(self, tables: Vec<&str>) -> Result<Self, sqlx::Error> {
// WriteOrDatabaseError
todo!();
Ok(self)
}

/// Given a table name and a row as JSON,
/// return the validated row.
/// Return an error on database problem.
pub fn validate_row(self, table_name: &str, row: &ValveRow) -> Result<ValveRow, sqlx::Error> {
// DatabaseError
todo!();
}

/// Given a table name and a row as JSON,
/// add the row to the table in the database,
/// and return the validated row, including its new row_number.
/// Return an error invalid table name or database problem.
pub fn insert_row(self, table_name: &str, row: &ValveRow) -> Result<ValveRow, sqlx::Error> {
// ConfigOrDatabaseError
todo!();
}

/// Given a table name, a row number, and a row as JSON,
/// update the row in the database,
/// and return the validated row.
/// Return an error invalid table name or row number or database problem.
pub fn update_row(
self,
table_name: &str,
row_number: usize,
row: &ValveRow,
) -> Result<ValveRow, sqlx::Error> {
// ConfigOrDatabaseError
todo!();
}

/// Given a table name and a row number,
/// delete that row from the table.
/// Return an error invalid table name or row number or database problem.
pub fn delete_row(self, table_name: &str, row_number: usize) -> Result<(), sqlx::Error> {
// ConfigOrDatabaseError
todo!();
}

/// Return the next change to undo, or None.
/// Return an error on database problem.
pub fn get_record_to_undo(self) -> Result<Option<AnyRow>, sqlx::Error> {
// DatabaseError
todo!();
}

/// Return the next change to redo, or None.
/// Return an error on database problem.
pub fn get_record_to_redo(self) -> Result<Option<AnyRow>, sqlx::Error> {
// DatabaseError
todo!();
}

/// Undo one change and return the change record
/// or None if there was no change to undo.
/// Return an error on database problem.
pub fn undo(self) -> Result<Option<ValveRow>, sqlx::Error> {
// DatabaseError
todo!();
}

/// Redo one change and return the change record
/// or None if there was no change to redo.
/// Return an error on database problem.
pub fn redo(self) -> Result<Option<ValveRow>, sqlx::Error> {
// DatabaseError
todo!();
}
}

/// Represents a structure such as those found in the `structure` column of the `column` table in
/// both its parsed format (i.e., as an [Expression](ast/enum.Expression.html)) as well as in its
/// original format (i.e., as a plain String).
Expand Down

0 comments on commit c20bca7

Please sign in to comment.