Changed database to a less generic name.

This commit is contained in:
Jeff Baskin 2022-07-11 09:13:43 -04:00
parent 5839cb93a2
commit 450e4fb53d
2 changed files with 13 additions and 13 deletions

View File

@ -69,11 +69,11 @@ impl Mutation {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct Database { pub struct MoreThanText {
schema: Schema<Query, Mutation, EmptySubscription>, schema: Schema<Query, Mutation, EmptySubscription>,
} }
impl Database { impl MoreThanText {
pub fn new() -> Self { pub fn new() -> Self {
let tables: Vec<Table> = Vec::new(); let tables: Vec<Table> = Vec::new();
Self { Self {
@ -93,7 +93,7 @@ impl Database {
mod support { mod support {
use super::*; use super::*;
pub fn compare(db: &Database, output: &str, expected: &str) { pub fn compare(db: &MoreThanText, output: &str, expected: &str) {
assert!( assert!(
output == expected, output == expected,
"\n\n{}\nGot: {}\nWant: {}\n\n", "\n\n{}\nGot: {}\nWant: {}\n\n",
@ -110,7 +110,7 @@ mod queries {
#[async_std::test] #[async_std::test]
async fn list_table() { async fn list_table() {
let db = Database::new(); let db = MoreThanText::new();
db.execute(r#"mutation {createTable(name: "wilma"){name}}"#) db.execute(r#"mutation {createTable(name: "wilma"){name}}"#)
.await; .await;
db.execute(r#"mutation {createTable(name: "betty"){name}}"#) db.execute(r#"mutation {createTable(name: "betty"){name}}"#)
@ -122,7 +122,7 @@ mod queries {
#[async_std::test] #[async_std::test]
async fn list_no_table() { async fn list_no_table() {
let db = Database::new(); let db = MoreThanText::new();
let output = db.execute(r#"{table(name: "slade"){name}}"#).await; let output = db.execute(r#"{table(name: "slade"){name}}"#).await;
let expected = r#"{"data":{"table":null}}"#; let expected = r#"{"data":{"table":null}}"#;
support::compare(&db, &output, &expected); support::compare(&db, &output, &expected);
@ -130,7 +130,7 @@ mod queries {
#[async_std::test] #[async_std::test]
async fn list_tables() { async fn list_tables() {
let db = Database::new(); let db = MoreThanText::new();
db.execute(r#"mutation {createTable(name: "fred"){name}}"#) db.execute(r#"mutation {createTable(name: "fred"){name}}"#)
.await; .await;
db.execute(r#"mutation {createTable(name: "barney"){name}}"#) db.execute(r#"mutation {createTable(name: "barney"){name}}"#)
@ -142,7 +142,7 @@ mod queries {
#[async_std::test] #[async_std::test]
async fn empty_table_description() { async fn empty_table_description() {
let db = Database::new(); let db = MoreThanText::new();
let output = db let output = db
.execute(r#"mutation {createTable(name: "pebbles"){name describe}}"#) .execute(r#"mutation {createTable(name: "pebbles"){name describe}}"#)
.await; .await;
@ -157,7 +157,7 @@ mod mutations {
#[async_std::test] #[async_std::test]
async fn add_table() { async fn add_table() {
let db = Database::new(); let db = MoreThanText::new();
let output = db let output = db
.execute(r#"mutation {createTable(name: "william"){name}}"#) .execute(r#"mutation {createTable(name: "william"){name}}"#)
.await; .await;
@ -167,7 +167,7 @@ mod mutations {
#[async_std::test] #[async_std::test]
async fn cannot_add_duplicate_table() { async fn cannot_add_duplicate_table() {
let db = Database::new(); let db = MoreThanText::new();
let qry = r#"mutation {createTable(name: "gadzoo"){name}}"#; let qry = r#"mutation {createTable(name: "gadzoo"){name}}"#;
db.execute(&qry).await; db.execute(&qry).await;
let output = db.execute(qry).await; let output = db.execute(qry).await;

View File

@ -7,7 +7,7 @@ use tide::{
mod database; mod database;
mod settings; mod settings;
use database::Database; use database::MoreThanText;
use settings::Settings; use settings::Settings;
#[async_std::main] #[async_std::main]
@ -19,8 +19,8 @@ async fn main() -> tide::Result<()> {
Ok(()) Ok(())
} }
async fn app_setup() -> tide::Server<Database> { async fn app_setup() -> tide::Server<MoreThanText> {
let db = Database::new(); let db = MoreThanText::new();
let mut app = tide::with_state(db); let mut app = tide::with_state(db);
app.at("/").get(home); app.at("/").get(home);
app.with( app.with(
@ -30,7 +30,7 @@ async fn app_setup() -> tide::Server<Database> {
return app; return app;
} }
async fn home(_req: Request<Database>) -> tide::Result { async fn home(_req: Request<MoreThanText>) -> tide::Result {
let mut res = Response::new(StatusCode::Ok); let mut res = Response::new(StatusCode::Ok);
res.set_body("<!DOCTYPE html> res.set_body("<!DOCTYPE html>
<html> <html>