Skip to content

Commit

Permalink
Add info structure (#3876)
Browse files Browse the repository at this point in the history
Co-authored-by: Micha de Vries <micha@devrie.sh>
  • Loading branch information
RaphaelDarley and kearfy committed Apr 16, 2024
1 parent 2c08715 commit 048ddb9
Show file tree
Hide file tree
Showing 33 changed files with 804 additions and 26 deletions.
7 changes: 7 additions & 0 deletions core/src/sql/algorithm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::sql::statements::info::InfoStructure;
use crate::sql::Value;
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt;
Expand Down Expand Up @@ -49,3 +51,8 @@ impl fmt::Display for Algorithm {
})
}
}
impl InfoStructure for Algorithm {
fn structure(self) -> Value {
self.to_string().into()
}
}
8 changes: 7 additions & 1 deletion core/src/sql/base.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::sql::Ident;
use crate::sql::statements::info::InfoStructure;
use crate::sql::{Ident, Value};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt;
Expand Down Expand Up @@ -30,3 +31,8 @@ impl fmt::Display for Base {
}
}
}
impl InfoStructure for Base {
fn structure(self) -> Value {
self.to_string().into()
}
}
6 changes: 6 additions & 0 deletions core/src/sql/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::sql::fmt::{is_pretty, pretty_indent, Fmt, Pretty};
use crate::sql::statements::info::InfoStructure;
use crate::sql::statements::{
BreakStatement, ContinueStatement, CreateStatement, DefineStatement, DeleteStatement,
ForeachStatement, IfelseStatement, InsertStatement, OutputStatement, RelateStatement,
Expand Down Expand Up @@ -166,6 +167,11 @@ impl Display for Block {
}
}

impl InfoStructure for Block {
fn structure(self) -> Value {
self.to_string().into()
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[revisioned(revision = 1)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
Expand Down
7 changes: 7 additions & 0 deletions core/src/sql/changefeed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::sql::duration::Duration;
use crate::sql::statements::info::InfoStructure;
use crate::sql::Value;
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
Expand Down Expand Up @@ -31,3 +33,8 @@ impl Default for ChangeFeed {
}
}
}
impl InfoStructure for ChangeFeed {
fn structure(self) -> Value {
self.to_string().into()
}
}
6 changes: 6 additions & 0 deletions core/src/sql/cond.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::sql::statements::info::InfoStructure;
use crate::sql::value::Value;
use revision::revisioned;
use serde::{Deserialize, Serialize};
Expand All @@ -22,3 +23,8 @@ impl fmt::Display for Cond {
write!(f, "WHERE {}", self.0)
}
}
impl InfoStructure for Cond {
fn structure(self) -> Value {
self.0.structure()
}
}
7 changes: 7 additions & 0 deletions core/src/sql/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::sql::fmt::Fmt;
use crate::sql::idiom::Idiom;
use crate::sql::statements::info::InfoStructure;
use crate::sql::Value;
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
Expand Down Expand Up @@ -32,6 +34,11 @@ impl fmt::Display for Fetchs {
}
}

impl InfoStructure for Fetchs {
fn structure(self) -> Value {
Value::Array(self.0.into_iter().map(|f| f.0.structure()).collect())
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
#[revisioned(revision = 1)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
Expand Down
6 changes: 6 additions & 0 deletions core/src/sql/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::ctx::Context;
use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::sql::statements::info::InfoStructure;
use crate::sql::{fmt::Fmt, Idiom, Part, Value};
use crate::syn;
use revision::revisioned;
Expand Down Expand Up @@ -65,6 +66,11 @@ impl Display for Fields {
}
}

impl InfoStructure for Fields {
fn structure(self) -> Value {
self.to_string().into()
}
}
impl Fields {
/// Process this type returning a computed simple Value
pub(crate) async fn compute(
Expand Down
9 changes: 8 additions & 1 deletion core/src/sql/ident.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::sql::{escape::escape_ident, strand::no_nul_bytes};
use crate::sql::statements::info::InfoStructure;
use crate::sql::{escape::escape_ident, strand::no_nul_bytes, Value};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
Expand Down Expand Up @@ -58,3 +59,9 @@ impl Display for Ident {
Display::fmt(&escape_ident(&self.0), f)
}
}

impl InfoStructure for Ident {
fn structure(self) -> Value {
self.0.into()
}
}
13 changes: 13 additions & 0 deletions core/src/sql/idiom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::ctx::Context;
use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::sql::statements::info::InfoStructure;
use crate::sql::{
fmt::{fmt_separated_by, Fmt},
part::Next,
Expand Down Expand Up @@ -199,3 +200,15 @@ impl Display for Idiom {
)
}
}

impl InfoStructure for Idioms {
fn structure(self) -> Value {
self.to_string().into()
}
}

impl InfoStructure for Idiom {
fn structure(self) -> Value {
self.to_string().into()
}
}
9 changes: 8 additions & 1 deletion core/src/sql/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::fnc::util::math::vector::{
};
use crate::sql::ident::Ident;
use crate::sql::scoring::Scoring;
use crate::sql::Number;
use crate::sql::statements::info::InfoStructure;
use crate::sql::{Number, Value};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt;
Expand Down Expand Up @@ -204,3 +205,9 @@ impl Display for Index {
}
}
}

impl InfoStructure for Index {
fn structure(self) -> Value {
self.to_string().into()
}
}
9 changes: 8 additions & 1 deletion core/src/sql/kind.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::sql::{fmt::Fmt, Table};
use crate::sql::statements::info::InfoStructure;
use crate::sql::{fmt::Fmt, Table, Value};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
Expand Down Expand Up @@ -130,3 +131,9 @@ impl Display for Kind {
}
}
}

impl InfoStructure for Kind {
fn structure(self) -> Value {
self.to_string().into()
}
}
32 changes: 31 additions & 1 deletion core/src/sql/permission.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::sql::fmt::is_pretty;
use crate::sql::fmt::pretty_indent;
use crate::sql::fmt::pretty_sequence_item;
use crate::sql::Value;
use crate::sql::statements::info::InfoStructure;
use crate::sql::{Object, Value};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::Write;
Expand Down Expand Up @@ -166,3 +167,32 @@ impl Display for Permission {
}
}
}

impl InfoStructure for Permission {
fn structure(self) -> Value {
match self {
Permission::None => Value::Bool(false),
Permission::Full => Value::Bool(true),
Permission::Specific(v) => Value::Strand(v.to_string().into()),
}
}
}

impl InfoStructure for Permissions {
fn structure(self) -> Value {
let Self {
select,
create,
update,
delete,
} = self;
let mut acc = Object::default();

acc.insert("select".to_string(), select.structure());
acc.insert("create".to_string(), create.structure());
acc.insert("update".to_string(), update.structure());
acc.insert("delete".to_string(), delete.structure());

Value::Object(acc)
}
}
43 changes: 42 additions & 1 deletion core/src/sql/statements/define/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::iam::{Action, ResourceKind};
use crate::sql::{filter::Filter, tokenizer::Tokenizer, Base, Ident, Strand, Value};
use crate::sql::statements::info::InfoStructure;
use crate::sql::{filter::Filter, tokenizer::Tokenizer, Base, Ident, Object, Strand, Value};
use derive::Store;
use revision::revisioned;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -89,3 +90,43 @@ impl Display for DefineAnalyzerStatement {
Ok(())
}
}

impl InfoStructure for DefineAnalyzerStatement {
fn structure(self) -> Value {
let Self {
name,
function,
tokenizers,
filters,
comment,
..
} = self;
let mut acc = Object::default();

acc.insert("name".to_string(), name.structure());

if let Some(function) = function {
acc.insert("function".to_string(), function.structure());
}

if let Some(tokenizers) = tokenizers {
acc.insert(
"tokenizers".to_string(),
Value::Array(tokenizers.into_iter().map(|t| t.to_string().into()).collect()),
);
}

if let Some(filters) = filters {
acc.insert(
"filters".to_string(),
Value::Array(filters.into_iter().map(|f| f.to_string().into()).collect()),
);
}

if let Some(comment) = comment {
acc.insert("comment".to_string(), comment.into());
}

Value::Object(acc)
}
}
22 changes: 21 additions & 1 deletion core/src/sql/statements/define/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::iam::{Action, ResourceKind};
use crate::sql::{changefeed::ChangeFeed, Base, Ident, Strand, Value};
use crate::sql::statements::info::InfoStructure;
use crate::sql::{changefeed::ChangeFeed, Base, Ident, Object, Strand, Value};
use derive::Store;
use revision::revisioned;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -87,3 +88,22 @@ impl Display for DefineDatabaseStatement {
Ok(())
}
}

impl InfoStructure for DefineDatabaseStatement {
fn structure(self) -> Value {
let Self {
name,
comment,
..
} = self;
let mut acc = Object::default();

acc.insert("name".to_string(), name.structure());

if let Some(comment) = comment {
acc.insert("comment".to_string(), comment.into());
}

Value::Object(acc)
}
}
34 changes: 33 additions & 1 deletion core/src/sql/statements/define/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::iam::{Action, ResourceKind};
use crate::sql::{Base, Ident, Strand, Value, Values};
use crate::sql::statements::info::InfoStructure;
use crate::sql::{Base, Ident, Object, Strand, Value, Values};
use derive::Store;
use revision::revisioned;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -80,3 +81,34 @@ impl Display for DefineEventStatement {
Ok(())
}
}

impl InfoStructure for DefineEventStatement {
fn structure(self) -> Value {
let Self {
name,
what,
when,
then,
comment,
..
} = self;
let mut acc = Object::default();

acc.insert("name".to_string(), name.structure());

acc.insert("what".to_string(), what.structure());

acc.insert("when".to_string(), when.structure());

acc.insert(
"then".to_string(),
Value::Array(then.0.iter().map(|v| v.to_string().into()).collect()),
);

if let Some(comment) = comment {
acc.insert("comment".to_string(), comment.into());
}

Value::Object(acc)
}
}
Loading

0 comments on commit 048ddb9

Please sign in to comment.