Enable RETURN statements in subqueries

Related to #1319
This commit is contained in:
Tobie Morgan Hitchcock 2023-02-19 19:41:20 +00:00
parent f7dd73212d
commit 275cf18a3a

View file

@ -8,6 +8,7 @@ use crate::sql::statements::create::{create, CreateStatement};
use crate::sql::statements::delete::{delete, DeleteStatement}; use crate::sql::statements::delete::{delete, DeleteStatement};
use crate::sql::statements::ifelse::{ifelse, IfelseStatement}; use crate::sql::statements::ifelse::{ifelse, IfelseStatement};
use crate::sql::statements::insert::{insert, InsertStatement}; use crate::sql::statements::insert::{insert, InsertStatement};
use crate::sql::statements::output::{output, OutputStatement};
use crate::sql::statements::relate::{relate, RelateStatement}; use crate::sql::statements::relate::{relate, RelateStatement};
use crate::sql::statements::select::{select, SelectStatement}; use crate::sql::statements::select::{select, SelectStatement};
use crate::sql::statements::update::{update, UpdateStatement}; use crate::sql::statements::update::{update, UpdateStatement};
@ -23,6 +24,7 @@ use std::fmt::{self, Display, Formatter};
pub enum Subquery { pub enum Subquery {
Value(Value), Value(Value),
Ifelse(IfelseStatement), Ifelse(IfelseStatement),
Output(OutputStatement),
Select(SelectStatement), Select(SelectStatement),
Create(CreateStatement), Create(CreateStatement),
Update(UpdateStatement), Update(UpdateStatement),
@ -43,6 +45,7 @@ impl Subquery {
match self { match self {
Self::Value(v) => v.writeable(), Self::Value(v) => v.writeable(),
Self::Ifelse(v) => v.writeable(), Self::Ifelse(v) => v.writeable(),
Self::Output(v) => v.writeable(),
Self::Select(v) => v.writeable(), Self::Select(v) => v.writeable(),
Self::Create(v) => v.writeable(), Self::Create(v) => v.writeable(),
Self::Update(v) => v.writeable(), Self::Update(v) => v.writeable(),
@ -65,6 +68,7 @@ impl Subquery {
match self { match self {
Self::Value(ref v) => v.compute(ctx, opt, txn, doc).await, Self::Value(ref v) => v.compute(ctx, opt, txn, doc).await,
Self::Ifelse(ref v) => v.compute(ctx, opt, txn, doc).await, Self::Ifelse(ref v) => v.compute(ctx, opt, txn, doc).await,
Self::Output(ref v) => v.compute(ctx, opt, txn, doc).await,
Self::Select(ref v) => { Self::Select(ref v) => {
// Is this a single output? // Is this a single output?
let one = v.single(); let one = v.single();
@ -205,6 +209,7 @@ impl Display for Subquery {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self { match self {
Self::Value(v) => write!(f, "({v})"), Self::Value(v) => write!(f, "({v})"),
Self::Output(v) => write!(f, "({v})"),
Self::Select(v) => write!(f, "({v})"), Self::Select(v) => write!(f, "({v})"),
Self::Create(v) => write!(f, "({v})"), Self::Create(v) => write!(f, "({v})"),
Self::Update(v) => write!(f, "({v})"), Self::Update(v) => write!(f, "({v})"),
@ -229,6 +234,7 @@ fn subquery_others(i: &str) -> IResult<&str, Subquery> {
let (i, _) = char('(')(i)?; let (i, _) = char('(')(i)?;
let (i, _) = mightbespace(i)?; let (i, _) = mightbespace(i)?;
let (i, v) = alt(( let (i, v) = alt((
map(output, Subquery::Output),
map(select, Subquery::Select), map(select, Subquery::Select),
map(create, Subquery::Create), map(create, Subquery::Create),
map(update, Subquery::Update), map(update, Subquery::Update),