Enable inspecting the current table

next
Sayan Nandan 3 years ago
parent ced5e75182
commit 82420e2013
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -7,6 +7,7 @@ All changes in this project will be noted in this file.
### Additions
- `INSPECT KEYSPACE` without arguments to inspect the current keyspace
- `INSPECT TABLE` without arguments to inspect the current table
### Fixes

@ -201,6 +201,12 @@ impl Corestore {
pub fn get_ctable(&self) -> Option<Arc<Table>> {
self.estate.table.as_ref().map(|(_, tbl)| tbl.clone())
}
pub fn get_table_result(&self) -> KeyspaceResult<&Table> {
match self.estate.table {
Some((_, ref table)) => Ok(table),
_ => Err(DdlError::DefaultNotFound),
}
}
pub fn get_ctable_ref(&self) -> Option<&Table> {
self.estate.table.as_ref().map(|(_, tbl)| tbl.as_ref())
}

@ -102,13 +102,17 @@ action! {
/// INSPECT a table. This should only have the table ID
fn inspect_table(handle: &Corestore, con: &'a mut T, mut act: ActionIter<'a>) {
ensure_length(act.len(), |len| len == 1)?;
ensure_length(act.len(), |len| len < 2)?;
match act.next() {
Some(entity) => {
let entity = handle_entity!(con, entity);
conwrite!(con, get_tbl!(entity, handle, con).describe_self())?;
},
None => aerr!(con),
None => {
// inspect the current table
let tbl = handle.get_table_result()?;
con.write_response(tbl.describe_self()).await?;
},
}
Ok(())
}

@ -24,6 +24,8 @@
*
*/
const TABLE_DECL_KM_STR_STR_VOLATILE: &str = "Keymap { data:(str,str), volatile:true }";
#[sky_macros::dbtest_module]
mod __private {
use skytable::{types::Array, Element, RespCode};
@ -56,18 +58,24 @@ mod __private {
query.push(__MYTABLE__);
match con.run_query_raw(&query).await.unwrap() {
Element::String(st) => {
assert_eq!(st, "Keymap { data:(str,str), volatile:true }".to_owned())
assert_eq!(st, TABLE_DECL_KM_STR_STR_VOLATILE.to_owned())
}
_ => panic!("Bad response for inspect table"),
}
}
async fn test_inspect_current_table() {
query.push("INSPECT");
query.push("TABLE");
let ret: String = con.run_query(&query).await.unwrap();
assert_eq!(ret, TABLE_DECL_KM_STR_STR_VOLATILE);
}
async fn test_inspect_table_fully_qualified_entity() {
query.push("INSPECT");
query.push("TABLE");
query.push(__MYENTITY__);
match con.run_query_raw(&query).await.unwrap() {
Element::String(st) => {
assert_eq!(st, "Keymap { data:(str,str), volatile:true }".to_owned())
assert_eq!(st, TABLE_DECL_KM_STR_STR_VOLATILE.to_owned())
}
_ => panic!("Bad response for inspect table"),
}

@ -75,9 +75,11 @@ pub fn dbtest_module(args: TokenStream, item: TokenStream) -> TokenStream {
///
/// ## _Ghost_ values
/// This macro gives:
/// - a `skytable::AsyncConnection` accessible by the `con` variable
/// - a mutable `skytable::Query` accessible by the `query` variable
/// - the current entity, accessible by `__MYENTITY__`
/// - `con`: a `skytable::AsyncConnection`
/// - `query`: a mutable `skytable::Query`
/// - `__MYENTITY__`: the entity set on launch
/// - `__MYTABLE__`: the table set on launch
/// - `__MYKS__`: the keyspace set on launch
///
/// ## Requirements
///

Loading…
Cancel
Save