Got use to return a database.
This commit is contained in:
parent
1829ff8c4a
commit
2da67487b5
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
*.swp
|
*.sw*
|
||||||
tests/data
|
tests/data
|
||||||
|
@ -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;
|
let databases = self.databases.read().await;
|
||||||
match databases.get(name) {
|
match databases.get(name) {
|
||||||
Some(_) => Ok(()),
|
Some(db) => Ok(db.clone()),
|
||||||
None => Err(DBError::new("database name not found")),
|
None => Err(DBError::new("database name not found")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct Database;
|
struct Database;
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
@ -44,12 +45,9 @@ impl Database {
|
|||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_column(&self, _name: &str) {
|
async fn add_table(&self, _name: &str) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod engine_functions {
|
mod engine_functions {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -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)]
|
#[cfg(test)]
|
||||||
@ -121,8 +128,8 @@ mod database_functions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn new_ccolumn() {
|
async fn new_table() {
|
||||||
let db = Database::new().await;
|
let db = Database::new().await;
|
||||||
db.add_column("fred").await;
|
db.add_table("fred").await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user