-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add basic examples * fix naming * fix default value * run examples in CI * chore
- Loading branch information
1 parent
b50e7c0
commit e96b85f
Showing
8 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SELECT | ||
* | ||
FROM | ||
`table`; | ||
|
||
ok | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SELECT | ||
* | ||
FROM | ||
`table`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. | ||
|
||
use std::{env, fmt::Display, process}; | ||
|
||
use async_trait::async_trait; | ||
use sqlness::{Database, Environment, Runner, SqlnessError}; | ||
|
||
struct MyEnv; | ||
struct MyDB; | ||
|
||
#[async_trait] | ||
impl Database for MyDB { | ||
async fn query(&self, query: String) -> Box<dyn Display> { | ||
// Implement query logic here | ||
println!("Exec {}...", query); | ||
return Box::new("ok".to_string()); | ||
} | ||
} | ||
|
||
impl MyDB { | ||
fn new(_env: &str, _config: Option<String>) -> Self { | ||
MyDB | ||
} | ||
|
||
fn stop(self) { | ||
println!("MyDB stopped..."); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Environment for MyEnv { | ||
type DB = MyDB; | ||
|
||
async fn start(&self, env: &str, config: Option<String>) -> Self::DB { | ||
println!("MyEnv start, env:{}, config:{:?}", env, config); | ||
MyDB::new(env, config) | ||
} | ||
|
||
async fn stop(&self, env: &str, database: Self::DB) { | ||
println!("MyEnv stop, env:{}", env,); | ||
database.stop(); | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), SqlnessError> { | ||
let args: Vec<String> = env::args().collect(); | ||
if args.len() < 2 { | ||
println!("Usage: {} config-path", args[0]); | ||
process::exit(1); | ||
} | ||
|
||
let env = MyEnv; | ||
let config_path = &args[1]; | ||
let runner = Runner::new(config_path, env) | ||
.await | ||
.expect("Create Runner failed"); | ||
|
||
println!("Run testcase..."); | ||
|
||
runner.run().await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
case_dir = "examples/basic-case" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters