-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example for running queries via vtgate
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use anyhow::Result; | ||
use vitess_grpc::query::BoundQuery; | ||
use vitess_grpc::vtgateservice::vitess_client::VitessClient; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// See docker-compose.yml for the details of the vitess deployment | ||
let vitess_url = "http://127.0.0.1:15301"; | ||
|
||
// Connect to Vitess | ||
let mut client = VitessClient::connect(vitess_url) | ||
.await | ||
.expect("Failed to connect to Vitess"); | ||
|
||
// Prepare the query to be executed | ||
let exec_request = vitess_grpc::vtgate::ExecuteRequest { | ||
query: Some(BoundQuery { | ||
sql: "SHOW TABLES FROM commerce".into(), | ||
..Default::default() | ||
}), | ||
..Default::default() | ||
}; | ||
|
||
// Execute the query | ||
let res = client.execute(exec_request).await?; | ||
|
||
// Print the results | ||
if let Some(result) = res.into_inner().result { | ||
let fields = result.fields; | ||
println!("fields: {:?}", fields); | ||
|
||
for row in result.rows { | ||
println!("row: {:?}", row); | ||
} | ||
} else { | ||
println!("no result"); | ||
} | ||
|
||
Ok(()) | ||
} |