Drop the sql::v1 module from the core library (#3683)

This commit is contained in:
Rushmore Mushambi 2024-03-15 16:37:27 +02:00 committed by GitHub
parent 65d8e6d422
commit 948b9640fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
698 changed files with 264 additions and 36999 deletions

View file

@ -41,7 +41,7 @@ kv-surrealkv = ["dep:surrealkv", "tokio/time"]
scripting = ["dep:js"] scripting = ["dep:js"]
http = ["dep:reqwest"] http = ["dep:reqwest"]
ml = ["dep:surrealml-core1", "dep:ndarray"] ml = ["dep:surrealml-core1", "dep:ndarray"]
jwks = ["dep:reqwest", "sql2"] jwks = ["dep:reqwest"]
arbitrary = [ arbitrary = [
"dep:arbitrary", "dep:arbitrary",
"dep:regex-syntax", "dep:regex-syntax",
@ -50,7 +50,6 @@ arbitrary = [
"uuid/arbitrary", "uuid/arbitrary",
] ]
experimental-parser = ["dep:phf", "dep:unicase"] experimental-parser = ["dep:phf", "dep:unicase"]
sql2 = []
# Private features # Private features
kv-fdb = ["tokio/time"] kv-fdb = ["tokio/time"]

View file

@ -32,7 +32,6 @@ impl<'a> Document<'a> {
// Get the input value // Get the input value
let inp = inp.pick(&k); let inp = inp.pick(&k);
// Check for READONLY clause // Check for READONLY clause
#[cfg(feature = "sql2")]
if fd.readonly && !self.is_new() && val != old { if fd.readonly && !self.is_new() && val != old {
return Err(Error::FieldReadonly { return Err(Error::FieldReadonly {
field: fd.name.clone(), field: fd.name.clone(),
@ -80,11 +79,7 @@ impl<'a> Document<'a> {
// Check for a VALUE clause // Check for a VALUE clause
if let Some(expr) = &fd.value { if let Some(expr) = &fd.value {
// Only run value clause for mutable and new fields // Only run value clause for mutable and new fields
#[cfg(feature = "sql2")] if !fd.readonly || self.is_new() {
let readonly = fd.readonly;
#[cfg(not(feature = "sql2"))]
let readonly = false;
if !readonly || self.is_new() {
// Configure the context // Configure the context
let mut ctx = Context::new(ctx); let mut ctx = Context::new(ctx);
ctx.add_value("input", &inp); ctx.add_value("input", &inp);

View file

@ -321,7 +321,6 @@ pub enum Error {
/// The requested event does not exist /// The requested event does not exist
#[error("The event '{value}' does not exist")] #[error("The event '{value}' does not exist")]
#[cfg(feature = "sql2")]
EvNotFound { EvNotFound {
value: String, value: String,
}, },
@ -334,7 +333,6 @@ pub enum Error {
/// The requested field does not exist /// The requested field does not exist
#[error("The field '{value}' does not exist")] #[error("The field '{value}' does not exist")]
#[cfg(feature = "sql2")]
FdNotFound { FdNotFound {
value: String, value: String,
}, },
@ -796,112 +794,96 @@ pub enum Error {
/// The requested analyzer already exists /// The requested analyzer already exists
#[error("The analyzer '{value}' already exists")] #[error("The analyzer '{value}' already exists")]
#[cfg(feature = "sql2")]
AzAlreadyExists { AzAlreadyExists {
value: String, value: String,
}, },
/// The requested database already exists /// The requested database already exists
#[error("The database '{value}' already exists")] #[error("The database '{value}' already exists")]
#[cfg(feature = "sql2")]
DbAlreadyExists { DbAlreadyExists {
value: String, value: String,
}, },
/// The requested event already exists /// The requested event already exists
#[error("The event '{value}' already exists")] #[error("The event '{value}' already exists")]
#[cfg(feature = "sql2")]
EvAlreadyExists { EvAlreadyExists {
value: String, value: String,
}, },
/// The requested field already exists /// The requested field already exists
#[error("The field '{value}' already exists")] #[error("The field '{value}' already exists")]
#[cfg(feature = "sql2")]
FdAlreadyExists { FdAlreadyExists {
value: String, value: String,
}, },
/// The requested function already exists /// The requested function already exists
#[error("The function 'fn::{value}' already exists")] #[error("The function 'fn::{value}' already exists")]
#[cfg(feature = "sql2")]
FcAlreadyExists { FcAlreadyExists {
value: String, value: String,
}, },
/// The requested index already exists /// The requested index already exists
#[error("The index '{value}' already exists")] #[error("The index '{value}' already exists")]
#[cfg(feature = "sql2")]
IxAlreadyExists { IxAlreadyExists {
value: String, value: String,
}, },
/// The requested model already exists /// The requested model already exists
#[error("The model '{value}' already exists")] #[error("The model '{value}' already exists")]
#[cfg(feature = "sql2")]
MlAlreadyExists { MlAlreadyExists {
value: String, value: String,
}, },
/// The requested namespace already exists /// The requested namespace already exists
#[error("The namespace '{value}' already exists")] #[error("The namespace '{value}' already exists")]
#[cfg(feature = "sql2")]
NsAlreadyExists { NsAlreadyExists {
value: String, value: String,
}, },
/// The requested param already exists /// The requested param already exists
#[error("The param '${value}' already exists")] #[error("The param '${value}' already exists")]
#[cfg(feature = "sql2")]
PaAlreadyExists { PaAlreadyExists {
value: String, value: String,
}, },
/// The requested scope already exists /// The requested scope already exists
#[error("The scope '{value}' already exists")] #[error("The scope '{value}' already exists")]
#[cfg(feature = "sql2")]
ScAlreadyExists { ScAlreadyExists {
value: String, value: String,
}, },
/// The requested table already exists /// The requested table already exists
#[error("The table '{value}' already exists")] #[error("The table '{value}' already exists")]
#[cfg(feature = "sql2")]
TbAlreadyExists { TbAlreadyExists {
value: String, value: String,
}, },
/// The requested namespace token already exists /// The requested namespace token already exists
#[error("The namespace token '{value}' already exists")] #[error("The namespace token '{value}' already exists")]
#[cfg(feature = "sql2")]
NtAlreadyExists { NtAlreadyExists {
value: String, value: String,
}, },
/// The requested database token already exists /// The requested database token already exists
#[error("The database token '{value}' already exists")] #[error("The database token '{value}' already exists")]
#[cfg(feature = "sql2")]
DtAlreadyExists { DtAlreadyExists {
value: String, value: String,
}, },
/// The requested scope token already exists /// The requested scope token already exists
#[error("The scope token '{value}' already exists")] #[error("The scope token '{value}' already exists")]
#[cfg(feature = "sql2")]
StAlreadyExists { StAlreadyExists {
value: String, value: String,
}, },
/// The requested user already exists /// The requested user already exists
#[error("The user '{value}' already exists")] #[error("The user '{value}' already exists")]
#[cfg(feature = "sql2")]
UserRootAlreadyExists { UserRootAlreadyExists {
value: String, value: String,
}, },
/// The requested namespace user already exists /// The requested namespace user already exists
#[error("The user '{value}' already exists in the namespace '{ns}'")] #[error("The user '{value}' already exists in the namespace '{ns}'")]
#[cfg(feature = "sql2")]
UserNsAlreadyExists { UserNsAlreadyExists {
value: String, value: String,
ns: String, ns: String,
@ -909,7 +891,6 @@ pub enum Error {
/// The requested database user already exists /// The requested database user already exists
#[error("The user '{value}' already exists in the database '{db}'")] #[error("The user '{value}' already exists in the database '{db}'")]
#[cfg(feature = "sql2")]
UserDbAlreadyExists { UserDbAlreadyExists {
value: String, value: String,
ns: String, ns: String,

View file

@ -3,7 +3,6 @@ use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc; use crate::doc::CursorDoc;
use crate::err::Error; use crate::err::Error;
use crate::idx::planner::executor::QueryExecutor; use crate::idx::planner::executor::QueryExecutor;
#[cfg(feature = "sql2")]
use crate::sql::value::TryRem; use crate::sql::value::TryRem;
use crate::sql::value::{TryAdd, TryDiv, TryMul, TryNeg, TryPow, TrySub, Value}; use crate::sql::value::{TryAdd, TryDiv, TryMul, TryNeg, TryPow, TrySub, Value};
use crate::sql::{Expression, Thing}; use crate::sql::{Expression, Thing};
@ -60,7 +59,6 @@ pub fn div(a: Value, b: Value) -> Result<Value, Error> {
a.try_div(b) a.try_div(b)
} }
#[cfg(feature = "sql2")]
pub fn rem(a: Value, b: Value) -> Result<Value, Error> { pub fn rem(a: Value, b: Value) -> Result<Value, Error> {
a.try_rem(b) a.try_rem(b)
} }

View file

@ -19,11 +19,7 @@ async fn config(
de_code: String, de_code: String,
_token_header: Header, _token_header: Header,
) -> Result<(DecodingKey, Validation), Error> { ) -> Result<(DecodingKey, Validation), Error> {
#[cfg(feature = "sql2")] if de_kind == Algorithm::Jwks {
let is_jwks = de_kind == Algorithm::Jwks;
#[cfg(not(feature = "sql2"))]
let is_jwks = false;
if is_jwks {
#[cfg(not(feature = "jwks"))] #[cfg(not(feature = "jwks"))]
{ {
warn!("Failed to verify a token defined as JWKS when the feature is not enabled"); warn!("Failed to verify a token defined as JWKS when the feature is not enabled");
@ -95,7 +91,6 @@ fn config_alg(algo: Algorithm, code: String) -> Result<(DecodingKey, Validation)
DecodingKey::from_rsa_pem(code.as_ref())?, DecodingKey::from_rsa_pem(code.as_ref())?,
Validation::new(jsonwebtoken::Algorithm::RS512), Validation::new(jsonwebtoken::Algorithm::RS512),
)), )),
#[cfg(feature = "sql2")]
Algorithm::Jwks => Err(Error::InvalidAuth), // We should never get here Algorithm::Jwks => Err(Error::InvalidAuth), // We should never get here
} }
} }

View file

@ -9,7 +9,6 @@ use crate::idx::ft::terms::{TermId, Terms};
use crate::sql::statements::DefineAnalyzerStatement; use crate::sql::statements::DefineAnalyzerStatement;
use crate::sql::tokenizer::Tokenizer as SqlTokenizer; use crate::sql::tokenizer::Tokenizer as SqlTokenizer;
use crate::sql::Value; use crate::sql::Value;
#[cfg(feature = "sql2")]
use crate::sql::{Function, Strand}; use crate::sql::{Function, Strand};
use async_recursion::async_recursion; use async_recursion::async_recursion;
use filter::Filter; use filter::Filter;
@ -20,7 +19,6 @@ mod filter;
mod tokenizer; mod tokenizer;
pub(crate) struct Analyzer { pub(crate) struct Analyzer {
#[cfg(feature = "sql2")]
function: Option<String>, function: Option<String>,
tokenizers: Option<Vec<SqlTokenizer>>, tokenizers: Option<Vec<SqlTokenizer>>,
filters: Option<Vec<Filter>>, filters: Option<Vec<Filter>>,
@ -29,7 +27,6 @@ pub(crate) struct Analyzer {
impl From<DefineAnalyzerStatement> for Analyzer { impl From<DefineAnalyzerStatement> for Analyzer {
fn from(az: DefineAnalyzerStatement) -> Self { fn from(az: DefineAnalyzerStatement) -> Self {
Self { Self {
#[cfg(feature = "sql2")]
function: az.function.map(|i| i.0), function: az.function.map(|i| i.0),
tokenizers: az.tokenizers, tokenizers: az.tokenizers,
filters: Filter::from(az.filters), filters: Filter::from(az.filters),
@ -198,7 +195,6 @@ impl Analyzer {
txn: &Transaction, txn: &Transaction,
mut input: String, mut input: String,
) -> Result<Tokens, Error> { ) -> Result<Tokens, Error> {
#[cfg(feature = "sql2")]
if let Some(function_name) = self.function.clone() { if let Some(function_name) = self.function.clone() {
let fns = Function::Custom(function_name.clone(), vec![Value::Strand(Strand(input))]); let fns = Function::Custom(function_name.clone(), vec![Value::Strand(Strand(input))]);
let val = fns.compute(ctx, opt, txn, None).await?; let val = fns.compute(ctx, opt, txn, None).await?;

View file

@ -70,7 +70,6 @@ async fn table_definitions_can_be_deleted() {
permissions: Default::default(), permissions: Default::default(),
changefeed: None, changefeed: None,
comment: None, comment: None,
#[cfg(feature = "sql2")]
if_not_exists: false, if_not_exists: false,
}; };
tx.set(&key, &value).await.unwrap(); tx.set(&key, &value).await.unwrap();

View file

@ -1939,7 +1939,6 @@ impl Transaction {
} }
/// Retrieve a specific function definition from a database. /// Retrieve a specific function definition from a database.
#[cfg(feature = "sql2")]
pub async fn get_db_function( pub async fn get_db_function(
&mut self, &mut self,
ns: &str, ns: &str,
@ -1954,7 +1953,6 @@ impl Transaction {
} }
/// Retrieve a specific function definition from a database. /// Retrieve a specific function definition from a database.
#[cfg(feature = "sql2")]
pub async fn get_db_param( pub async fn get_db_param(
&mut self, &mut self,
ns: &str, ns: &str,
@ -2044,7 +2042,6 @@ impl Transaction {
} }
/// Retrieve an event for a table. /// Retrieve an event for a table.
#[cfg(feature = "sql2")]
pub async fn get_tb_event( pub async fn get_tb_event(
&mut self, &mut self,
ns: &str, ns: &str,
@ -2062,7 +2059,6 @@ impl Transaction {
} }
/// Retrieve an event for a table. /// Retrieve an event for a table.
#[cfg(feature = "sql2")]
pub async fn get_tb_field( pub async fn get_tb_field(
&mut self, &mut self,
ns: &str, ns: &str,
@ -2080,7 +2076,6 @@ impl Transaction {
} }
/// Retrieve an event for a table. /// Retrieve an event for a table.
#[cfg(feature = "sql2")]
pub async fn get_tb_index( pub async fn get_tb_index(
&mut self, &mut self,
ns: &str, ns: &str,

View file

@ -289,7 +289,7 @@ impl Complement<Array> for Array {
// ------------------------------ // ------------------------------
#[cfg_attr(feature = "sql2", allow(dead_code))] #[allow(dead_code)]
pub(crate) trait Concat<T> { pub(crate) trait Concat<T> {
fn concat(self, other: T) -> T; fn concat(self, other: T) -> T;
} }

View file

@ -1,9 +1,155 @@
#[cfg(not(feature = "sql2"))] //! The full type definitions for the SurrealQL query language
mod v1;
#[cfg(not(feature = "sql2"))]
pub use v1::*;
#[cfg(feature = "sql2")] pub(crate) mod algorithm;
mod v2; #[cfg(feature = "arbitrary")]
#[cfg(feature = "sql2")] pub(crate) mod arbitrary;
pub use v2::*; pub(crate) mod array;
pub(crate) mod base;
pub(crate) mod block;
pub(crate) mod bytes;
pub(crate) mod cast;
pub(crate) mod change_feed_include;
pub(crate) mod changefeed;
pub(crate) mod cond;
pub(crate) mod constant;
pub(crate) mod data;
pub(crate) mod datetime;
pub(crate) mod dir;
pub(crate) mod duration;
pub(crate) mod edges;
pub(crate) mod escape;
pub(crate) mod explain;
pub(crate) mod expression;
pub(crate) mod fetch;
pub(crate) mod field;
pub(crate) mod filter;
pub(crate) mod fmt;
pub(crate) mod function;
pub(crate) mod future;
pub(crate) mod geometry;
pub(crate) mod graph;
pub(crate) mod group;
pub(crate) mod id;
pub(crate) mod ident;
pub(crate) mod idiom;
pub(crate) mod kind;
pub(crate) mod language;
pub(crate) mod limit;
pub(crate) mod mock;
pub(crate) mod model;
pub(crate) mod number;
pub(crate) mod object;
pub(crate) mod operation;
pub(crate) mod operator;
pub(crate) mod order;
pub(crate) mod output;
pub(crate) mod param;
pub(crate) mod part;
pub(crate) mod paths;
pub(crate) mod permission;
pub(crate) mod query;
pub(crate) mod range;
pub(crate) mod regex;
pub(crate) mod scoring;
pub(crate) mod script;
pub(crate) mod split;
pub(crate) mod start;
pub(crate) mod statement;
pub(crate) mod strand;
pub(crate) mod subquery;
pub(crate) mod table;
pub(crate) mod thing;
pub(crate) mod timeout;
pub(crate) mod tokenizer;
pub(crate) mod uuid;
pub(crate) mod value;
pub(crate) mod version;
pub(crate) mod view;
pub(crate) mod with;
#[doc(hidden)]
pub mod index;
pub mod serde;
pub mod statements;
pub use self::algorithm::Algorithm;
pub use self::array::Array;
pub use self::base::Base;
pub use self::block::Block;
pub use self::bytes::Bytes;
pub use self::cast::Cast;
pub use self::changefeed::ChangeFeed;
pub use self::cond::Cond;
pub use self::constant::Constant;
pub use self::data::Data;
pub use self::datetime::Datetime;
pub use self::dir::Dir;
pub use self::duration::Duration;
pub use self::edges::Edges;
pub use self::explain::Explain;
pub use self::expression::Expression;
pub use self::fetch::Fetch;
pub use self::fetch::Fetchs;
pub use self::field::Field;
pub use self::field::Fields;
pub use self::function::Function;
pub use self::future::Future;
pub use self::geometry::Geometry;
pub use self::graph::Graph;
pub use self::group::Group;
pub use self::group::Groups;
pub use self::id::Id;
pub use self::ident::Ident;
pub use self::idiom::Idiom;
pub use self::idiom::Idioms;
pub use self::index::Index;
pub use self::kind::Kind;
pub use self::limit::Limit;
pub use self::mock::Mock;
pub use self::model::Model;
pub use self::number::Number;
pub use self::object::Object;
pub use self::operation::Operation;
pub use self::operator::Operator;
pub use self::order::Order;
pub use self::order::Orders;
pub use self::output::Output;
pub use self::param::Param;
pub use self::part::Part;
pub use self::permission::Permission;
pub use self::permission::Permissions;
pub use self::query::Query;
pub use self::range::Range;
pub use self::regex::Regex;
pub use self::scoring::Scoring;
pub use self::script::Script;
pub use self::split::Split;
pub use self::split::Splits;
pub use self::start::Start;
pub use self::statement::Statement;
pub use self::statement::Statements;
pub use self::strand::Strand;
pub use self::subquery::Subquery;
pub use self::table::Table;
pub use self::table::Tables;
pub use self::thing::Thing;
pub use self::timeout::Timeout;
pub use self::tokenizer::Tokenizer;
pub use self::uuid::Uuid;
pub use self::value::serde::to_value;
#[doc(hidden)]
pub use self::value::serde::{from_value, FromValueError};
pub use self::value::Value;
pub use self::value::Values;
pub use self::version::Version;
pub use self::view::View;
pub use self::with::With;
// module reexporting parsing function to prevent a breaking change.
#[doc(hidden)]
mod parser {
pub use crate::syn::*;
}
pub use self::parser::{idiom, json, parse, subquery, thing, value};

View file

@ -124,7 +124,6 @@ impl fmt::Display for KillStatement {
} }
#[cfg(test)] #[cfg(test)]
#[cfg(feature = "sql2")]
mod test { mod test {
use std::str::FromStr; use std::str::FromStr;
@ -134,7 +133,7 @@ mod test {
use crate::kvs::lq_structs::{KillEntry, TrackedResult}; use crate::kvs::lq_structs::{KillEntry, TrackedResult};
use crate::kvs::{Datastore, LockType, TransactionType}; use crate::kvs::{Datastore, LockType, TransactionType};
use crate::sql::statements::KillStatement; use crate::sql::statements::KillStatement;
use crate::sql::v2::uuid::Uuid; use crate::sql::uuid::Uuid;
#[test_log::test(tokio::test)] #[test_log::test(tokio::test)]
async fn kill_handles_uuid_event_registration() { async fn kill_handles_uuid_event_registration() {
@ -151,7 +150,7 @@ mod test {
.with_db(Some("database".into())) .with_db(Some("database".into()))
.with_ns(Some("namespace".into())); .with_ns(Some("namespace".into()));
let ds = Datastore::new("memory").await.unwrap(); let ds = Datastore::new("memory").await.unwrap();
let mut tx = let tx =
ds.transaction(TransactionType::Write, LockType::Optimistic).await.unwrap().enclose(); ds.transaction(TransactionType::Write, LockType::Optimistic).await.unwrap().enclose();
res.compute(&ctx, &opt, &tx, None).await.unwrap(); res.compute(&ctx, &opt, &tx, None).await.unwrap();

Some files were not shown because too many files have changed in this diff Show more