Skip to content

Commit

Permalink
20231102-2-support kill , return , throw
Browse files Browse the repository at this point in the history
  • Loading branch information
syf20020816 committed Nov 2, 2023
1 parent d729d9e commit c0ee2d1
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 187 deletions.
38 changes: 7 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,12 @@ full = ["row", "builder", "surreal"]
- [x] <strong>Surrealism.toml支持</strong>
- [ ] <strong>自定义构建支持(SurrealismConfig)</strong>



### Init 初始化服务


- [x] <strong>DefaultInitService 默认初始化服务的支持</strong>
- [ ] <strong>自定义初始化服务的支持</strong>



### ID 表ID

- [x] <strong>SurrealID::Default的支持</strong>
Expand All @@ -269,8 +265,6 @@ full = ["row", "builder", "surreal"]
- [x] <strong>SurrealID::Range的支持</strong>




### Value 数据类型


Expand All @@ -292,8 +286,6 @@ full = ["row", "builder", "surreal"]
- [x] <strong>数学常数构建</strong>
- [x] <strong>数学常数支持</strong>



## Builder


Expand All @@ -318,19 +310,16 @@ full = ["row", "builder", "surreal"]
- [ ] <strong>FOR STMT</strong>
- [ ] <strong>BREAK STMT</strong>
- [ ] <strong>CONTINUE STMT</strong>
- [ ] <strong>KILL STMT</strong>
- [ ] <strong>THROW STMT</strong>


- [x] <strong>KILL STMT</strong>
- [x] <strong>THROW STMT</strong>
- [x] <strong>RETURN STMT</strong>

### Use


- [x] <strong>USE NS STMT</strong>
- [x] <strong>USE DB STMT</strong>



### Create


Expand All @@ -340,8 +329,6 @@ full = ["row", "builder", "surreal"]
- [x] <strong>TIMEOUT STMT</strong>
- [x] <strong>PARALLEL STMT</strong>



### Insert


Expand Down Expand Up @@ -386,8 +373,6 @@ full = ["row", "builder", "surreal"]
- [x] <strong>PARALLEL</strong>
- [ ] <strong>DELETE WITH RELETE</strong>



### Remove


Expand Down Expand Up @@ -435,8 +420,6 @@ full = ["row", "builder", "surreal"]
- [x] <strong>PARAM</strong>
- [x] <strong>ANALYZER</strong>



### Info


Expand All @@ -446,23 +429,17 @@ full = ["row", "builder", "surreal"]
- [x] <strong>SCOPE</strong>
- [x] <strong>TABLE</strong>



### Show


- [x] <strong>SINCE</strong>
- [x] <strong>LIMIT</strong>



### Sleep


- [x] <strong>Duration</strong>



## Assert


Expand All @@ -471,8 +448,6 @@ full = ["row", "builder", "surreal"]
- [x] <strong>Condition</strong>
- [x] <strong>Criteria</strong>



## Functions


Expand All @@ -495,8 +470,6 @@ full = ["row", "builder", "surreal"]
- [ ] <strong>Scripting</strong>
- [ ] <strong>Vector</strong>



## Row


Expand Down Expand Up @@ -552,8 +525,11 @@ full = ["row", "builder", "surreal"]

- 0.3.1:
- 重构Define语句且补全DEFINE ANALYSIS
- 支持Return语句
- 支持Kill语句
- 支持Throw语句
-

- 0.3.0:
- 重构init Service 和 config Service(Refactoring init service and config service)
- 优化SurrealValue(Optimize SurrealValue)
Expand Down
10 changes: 5 additions & 5 deletions surrealism/src/core/builder/define/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! ```
use std::fmt::{Display, Formatter};
use crate::db::constants::{BLANK, DEFINE_ANALYZER, FILTERS, STMT_END, TOKENIZERS};
use crate::db::constants::{DEFINE_ANALYZER, FILTERS, STMT_END, TOKENIZERS};

#[derive(Debug, Clone)]
pub struct DefineAnalyzer<'a> {
Expand Down Expand Up @@ -66,12 +66,12 @@ impl<'a> DefineAnalyzer<'a> {

impl<'a> Display for DefineAnalyzer<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f,"{} {}", DEFINE_ANALYZER, self.name);
write!(f, "{} {}", DEFINE_ANALYZER, self.name);
if let Some(tokenizers) = self.tokenizers.as_ref() {
write!(f," {} {}", TOKENIZERS, &tokenizers.join(", "));
write!(f, " {} {}", TOKENIZERS, &tokenizers.join(", "));
}
if let Some(filters) = self.filters.as_ref() {
write!(f," {} {}", FILTERS, filters.join(", "));
if let Some(filters) = self.filters.as_ref() {
write!(f, " {} {}", FILTERS, filters.join(", "));
}
write!(f, "{}", STMT_END)
}
Expand Down
2 changes: 1 addition & 1 deletion surrealism/src/core/builder/define/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! ```
use std::fmt::{Display, Formatter};
use super::{OnType};
use crate::db::{Condition, ValueConstructor};
use crate::db::{Condition};
use crate::db::constants::{DEFINE_EVENT, ON_TABLE, STMT_END, THEN, WHEN};

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion surrealism/src/core/builder/define/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


use std::fmt::{Display, Formatter};
use crate::db::constants::{DEFINE_FUNCTION, LEFT_BRACE, RETURN, RIGHT_BRACE, STMT_END};
use crate::db::constants::{DEFINE_FUNCTION, LEFT_BRACE, RIGHT_BRACE, STMT_END};

#[derive(Debug, Clone)]
pub struct DefineFunction<'a> {
Expand Down
2 changes: 1 addition & 1 deletion surrealism/src/core/builder/define/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub use index::{DefineIndex,UniqueSearch};

use std::fmt::{Display, Formatter};
use crate::db::{Condition, ParamCombine};
use crate::db::constants::{ROLES, DEFINE_USER, NAMESPACE, DATABASE, PASSHASH, PASSWORD, ROOT, TABLE, DEFINE_DB, DEFINE_NS, DEFINE_LOGIN, DEFINE_SCOPE, STMT_END, ON, TYPE, SCOPE, PS256, PS384, PS512, EDDSA, ES256, ES384, ES512, HS256, HS384, HS512, RS256, RS384, RS512, VALUE, DEFINE_TOKEN, SCHEMA_FULL, SCHEMA_LESS, SIGN_IN, SIGN_UP, DROP, DEFINE_TABLE, BLANK, NONE, FULL, FOR, DEFINE_EVENT, ON_TABLE, WHEN, THEN, DEFINE_FUNCTION, RETURN, DEFINE_FIELD, FIELDS, COLUMNS, DEFINE_INDEX, UNIQUE, DEFINE_PARAM};
use crate::db::constants::{ROLES, DEFINE_USER, NAMESPACE, DATABASE, PASSHASH, PASSWORD, ROOT, TABLE, DEFINE_DB, DEFINE_NS, DEFINE_LOGIN, DEFINE_SCOPE, STMT_END, ON, TYPE, SCOPE, PS256, PS384, PS512, EDDSA, ES256, ES384, ES512, HS256, HS384, HS512, RS256, RS384, RS512, VALUE, DEFINE_TOKEN, SCHEMA_FULL, SCHEMA_LESS, UNIQUE, DEFINE_PARAM, NONE, FULL, FOR, FIELDS, COLUMNS};



Expand Down
2 changes: 1 addition & 1 deletion surrealism/src/core/builder/define/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use super::{Permissions, Schema};
use std::fmt::{Display, Formatter};
use crate::db::constants::{BLANK, DEFINE_TABLE, DROP, STMT_END};
use crate::db::constants::{DEFINE_TABLE, DROP, STMT_END};
use crate::db::TimeUnit;

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion surrealism/src/core/builder/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use std::collections::{BTreeMap};
use serde::Serialize;
use crate::db::{Table, Criteria, SurrealValue, Object, SurrealID, ParamCombine, Set, Operator, InsertStrategy};
use crate::db::{Table, SurrealValue, Object, SurrealID, ParamCombine, Set, Operator, InsertStrategy};
use super::{BaseWrapperImpl, TableImpl};
use crate::db::constants::{STMT_END, INSERT_UPDATE, INSERT, BLANK, VALUES, INTO};
use crate::table_impl;
Expand Down
26 changes: 19 additions & 7 deletions surrealism/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl SQLBuilderFactory {
pub fn remove<'w>() -> RemoveWrapper<'w> {
RemoveWrapper::new()
}
pub fn show()->ShowWrapper{ShowWrapper::new()}
pub fn show() -> ShowWrapper { ShowWrapper::new() }
/// # make sleep statement
/// ## example
/// ```rust
Expand All @@ -89,12 +89,24 @@ impl SQLBuilderFactory {
/// Ok(())
/// }
/// ```
pub fn sleep(duration:SurrealValue)->String{
return if duration.is_duration(){
format!("SLEEP {}",duration.to_string())
}else{
pub fn sleep(duration: SurrealValue) -> String {
return if duration.is_duration() {
format!("SLEEP {}", duration.to_string())
} else {
panic!("SLEEP should use Duration")
}
};
}
/// THROW语句可用于在发生意外情况的地方抛出错误。查询的执行将中止,错误将返回给客户端。
pub fn throw(error_msg: &str) -> String {
format!("THROW {}", &SurrealValue::string(error_msg).to_string())
}
pub fn returned(value: SurrealValue) -> String {
format!("RETURN {}", value.to_string())
}
/// KILL 语句用于终止正在运行的实时查询
/// KILL 语句不接受值类型,则此值必须解析为UUID。 因此,它将接受UUID或参数的字符串文字。
pub fn kill(value: &str) -> String {
format!("KILL '{}'", value)
}
}

Expand All @@ -109,7 +121,7 @@ pub trait BaseWrapperImpl {
///
/// wrapper will build to String(Complete Statement)
fn build(&mut self) -> String;
fn build_as_child(&mut self)->String;
fn build_as_child(&mut self) -> String;
}

/// wrapper param need table:Table
Expand Down
6 changes: 3 additions & 3 deletions surrealism/src/core/builder/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::fmt::{Display, Formatter};
use crate::{timeout_lifetime_impl, parallel_lifetime_impl, table_lifetime_impl};
use crate::core::db::{Condition, Table, TimeOut, Order, Field, SurrealID, TimeUnit, ParamCombine};
use super::{TimeoutImpl, ParallelImpl, TableImpl, ConditionImpl, BaseWrapperImpl};
use crate::core::db::constants::{EXPLAIN, FULL, SELECT, STMT_END, BLANK, PARALLEL, ALL, GROUP_BY, ORDER_BY, SPLIT, START, LIMIT, FETCH, FROM, DIFF, LIVE_SELECT};
use crate::core::db::constants::{EXPLAIN, FULL, SELECT, STMT_END, BLANK, PARALLEL, GROUP_BY, ORDER_BY, SPLIT, START, LIMIT, FETCH, FROM, LIVE_SELECT};
use crate::db::With;

pub trait SelectWrapperImpl<'w>: TableImpl + ParallelImpl + ConditionImpl + TimeoutImpl + BaseWrapperImpl {
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'w> BaseWrapperImpl for SelectWrapper<'w> {

impl<'w> Display for SelectWrapper<'w> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut res = format!("{} {} {} {}", SELECT, &self.field.iter().map(|x|x.to_string()).collect::<Vec<String>>().join(", "), FROM, &self.table.combine());
let mut res = format!("{} {} {} {}", SELECT, &self.field.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(", "), FROM, &self.table.combine());
if self.omit.is_some() {
res.push_str(BLANK);

Expand Down Expand Up @@ -418,7 +418,7 @@ impl<'w> BaseWrapperImpl for LiveSelectWrapper<'w> {
}

fn build_as_child(&mut self) -> String {
let mut res = format!("{} {} {} {}", LIVE_SELECT, &self.field.iter().map(|x|x.to_string()).collect::<Vec<String>>().join(", "), FROM, &self.table.combine());
let mut res = format!("{} {} {} {}", LIVE_SELECT, &self.field.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(", "), FROM, &self.table.combine());
if self.condition.is_some() {
res.push_str(BLANK);
res.push_str(&self.condition.as_ref().unwrap().combine())
Expand Down
1 change: 0 additions & 1 deletion surrealism/src/core/db/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! ```
use std::fmt::{Display, Formatter};
use crate::db::constants::BLANK;
use crate::db::ParamCombine;
use super::constants::{ALL, DIFF};

Expand Down
2 changes: 0 additions & 2 deletions surrealism/src/core/db/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
//!
use std::collections::{BTreeMap, HashMap};
use std::fmt::{Display, Formatter};
use std::ops::Deref;
use num_traits::cast::FromPrimitive;
use std::str::FromStr;
use serde::{Serialize, Deserialize};
use serde_json::Value;
use surrealdb::sql::{Duration, Datetime};
Expand Down
6 changes: 3 additions & 3 deletions surrealism/src/core/db/with.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::{Display, Formatter};
use crate::db::constants::{BLANK, WITH_INDEX};
use super::constants::{WITH, WITH_NOINDEX};
use super::constants::{WITH_NOINDEX};

/// # With INDEX | NOINDEX
/// 查询规划器可以根据查询的结构和需求,用一个或多个索引迭代器替换标准的表迭代器。
Expand Down Expand Up @@ -61,8 +61,8 @@ impl<'w> Display for With<'w> {
match self {
With::NOINDEX => f.write_str(WITH_NOINDEX),
With::INDEX(index) => {
f.write_str(WITH_INDEX);
f.write_str(BLANK);
let _ = f.write_str(WITH_INDEX);
let _ = f.write_str(BLANK);
f.write_str(&index.join(", "))
}
}
Expand Down
Loading

0 comments on commit c0ee2d1

Please sign in to comment.