Got use to return a database.

This commit is contained in:
Jeff Baskin 2022-10-31 10:01:07 -04:00
parent 1829ff8c4a
commit 2da67487b5
2 changed files with 16 additions and 9 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
/target
*.swp
*.sw*
tests/data

View File

@ -28,15 +28,16 @@ impl MoreThanText {
}
}
async fn use_database(&self, name: &str) -> Result<(), DBError> {
async fn use_database(&self, name: &str) -> Result<Database, DBError> {
let databases = self.databases.read().await;
match databases.get(name) {
Some(_) => Ok(()),
Some(db) => Ok(db.clone()),
None => Err(DBError::new("database name not found")),
}
}
}
#[derive(Clone)]
struct Database;
impl Database {
@ -44,11 +45,8 @@ impl Database {
Self {}
}
async fn add_column(&self, _name: &str) {
async fn add_table(&self, _name: &str) {}
}
}
#[cfg(test)]
mod engine_functions {
@ -109,6 +107,15 @@ mod engine_functions {
}
}
}
#[async_std::test]
async fn create_get_table() {
let db = "thedatabase";
let mtt = MoreThanText::new().await;
mtt.create_database(db).await.unwrap();
let dbase = mtt.use_database(db).await.unwrap();
dbase.add_table("melvin").await;
}
}
#[cfg(test)]
@ -121,8 +128,8 @@ mod database_functions {
}
#[async_std::test]
async fn new_ccolumn() {
async fn new_table() {
let db = Database::new().await;
db.add_column("fred").await;
db.add_table("fred").await;
}
}