Skip to content

Commit

Permalink
Remove Row from Payload::Select, (gluesql#287)
Browse files Browse the repository at this point in the history
Row is useful only in execution layer codes, not a good idea to expose Row to db users.
Remove Row from Payload::Select, so it now returns Vec<Vec<Value>> for rows field.
  • Loading branch information
panarch authored Aug 12, 2021
1 parent 98c1534 commit f4bf7a1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
3 changes: 1 addition & 2 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ mod hello_world {
};

let first_row = &rows[0];
let first_row_unwrapped = &first_row.0;
let first_value = &first_row_unwrapped[0];
let first_value = &first_row[0];

/*
Row values are wrapped into a value enum, on the basis of the result type
Expand Down
3 changes: 1 addition & 2 deletions examples/sled_multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ mod sled_multi_threaded {
};

let first_row = &rows[0];
let first_row_unwrapped = &first_row.0;
let first_value = &first_row_unwrapped[0];
let first_value = &first_row[0];
let to_greet = match first_value {
Value::Str(to_greet) => to_greet,
value => panic!("Unexpected type: {:?}", value),
Expand Down
9 changes: 6 additions & 3 deletions src/executor/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
},
crate::{
ast::{Query, SetExpr, Statement, Values},
data::{get_name, Row, Schema},
data::{get_name, Row, Schema, Value},
result::{MutResult, Result},
store::{GStore, GStoreMut},
},
Expand Down Expand Up @@ -36,7 +36,7 @@ pub enum Payload {
Insert(usize),
Select {
labels: Vec<String>,
rows: Vec<Row>,
rows: Vec<Vec<Value>>,
},
Delete(usize),
Update(usize),
Expand Down Expand Up @@ -287,7 +287,10 @@ pub async fn execute<T: 'static + Debug, U: GStore<T> + GStoreMut<T>>(
Statement::Query(query) => {
let (labels, rows) = try_block!(storage, {
let (labels, rows) = select_with_labels(&storage, query, None, true).await?;
let rows = rows.try_collect::<Vec<_>>().await?;
let rows = rows
.map_ok(|Row(values)| values)
.try_collect::<Vec<_>>()
.await?;

Ok((labels, rows))
});
Expand Down
10 changes: 5 additions & 5 deletions src/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Glue {
#[cfg(test)]
mod tests {
use {
crate::{Glue, Payload, Row, SledStorage, Value},
crate::{Glue, Payload, SledStorage, Value},
std::convert::TryFrom,
};

Expand Down Expand Up @@ -83,16 +83,16 @@ mod tests {
Ok(Payload::Select {
labels: vec![String::from("id"), String::from("name"), String::from("is")],
rows: vec![
Row(vec![
vec![
Value::I64(1),
Value::Str(String::from("test1")),
Value::Bool(true)
]),
Row(vec![
],
vec![
Value::I64(2),
Value::Str(String::from("test2")),
Value::Bool(false)
])
]
]
})
);
Expand Down
10 changes: 5 additions & 5 deletions src/tests/macros.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[macro_export]
macro_rules! row {
( $( $p:path )* ; $( $v:expr )* ) => (
Row(vec![$( $p($v) ),*])
vec![$( $p($v) ),*]
)
}

Expand Down Expand Up @@ -88,12 +88,12 @@ macro_rules! select_with_null {
( $( $c: tt )|* ; $( $v: expr )* ) => (
Payload::Select {
labels: vec![$( stringify!($c).to_owned().replace("\"", "")),+],
rows: vec![Row(vec![$( $v ),*])],
rows: vec![vec![$( $v ),*]],
}
);
( $( $c: tt )|* ; $( $v: expr )* ; $( $( $v2: expr )* );*) => ({
let mut rows = vec![
Row(vec![$( $v ),*])
vec![$( $v ),*]
];

Payload::Select {
Expand All @@ -106,12 +106,12 @@ macro_rules! select_with_null {
#[macro_export]
macro_rules! concat_with_null {
( $rows: ident ; $( $v: expr )* ) => ({
$rows.push(Row(vec![$( $v ),*]));
$rows.push(vec![$( $v ),*]);

$rows
});
( $rows: ident ; $( $v: expr )* ; $( $( $v2: expr )* );* ) => ({
$rows.push(Row(vec![$( $v ),*]));
$rows.push(vec![$( $v ),*]);

concat_with_null!($rows ; $( $( $v2 )* );* )
});
Expand Down
5 changes: 1 addition & 4 deletions src/tests/tester.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
crate::{
ast::{Expr, IndexItem, Query, SetExpr, Statement, TableFactor},
data::{Row, Value},
data::Value,
executor::{execute, Payload},
parse_sql::{parse, parse_expr},
plan::plan,
Expand Down Expand Up @@ -62,9 +62,6 @@ pub fn test(expected: Result<Payload>, found: Result<Payload>) {
let rows = expected.into_iter().zip(found.into_iter()).enumerate();

for (i, (expected, found)) in rows {
let Row(expected) = expected;
let Row(found) = found;

assert_eq!(
expected.len(),
found.len(),
Expand Down

0 comments on commit f4bf7a1

Please sign in to comment.