Replies: 2 comments 4 replies
-
Hi @PlainBane thanks for starting this discussion! Just to check, is this specifically for embedded use-case yes? Would it be possible to give an example (even better with some fake code) that showed what/how/why you would do with this? |
Beta Was this translation helpful? Give feedback.
4 replies
-
But I think that can be done on your Backend logic,
I think it's best to think about like a mongodb, postgres server
Idk though 😁😁
…On Thu, Sep 8, 2022, 3:34 PM PlainBane ***@***.***> wrote:
@tobiemh <https://github.com/tobiemh>
I would use it in embedded. I will be building wrapper around the lib and
this could be nice way of intercepting queries if necessary. My use-case
would be more like browser -> backend -> SurrealDB/lib.
I could try some code, but I'm more of a Go dev. Just started with Rust.
The idea is to use it for any external logic. It could be custom access
policy validation, user input validation in case query variable validation
is not enough or not used. Allowing use of only select query features( only
allow SELECT ) without having to write access permissions in query for each
table.
Just more flexibility in embedded cases. Like actix or fiber let you
intercept http req and run custom logic before handler with access to req
data. I can add this in my in my own fork, it's just a suggestion.
Code could be something like this:
// This would be like a callback signature or something optional.
// I don't know how to do this in rust properly. Defined externally, outside lib.
// Maybe passed in fn execute() as signature
fn try_middleware(txt: &str, sess: &Session, vars: Variables) -> Result<(), Error> {
// Do some custom logic here
Ok(())
}
### In lib/src/kvs/ds.rs ~ line: 297
pub async fn execute(
&self,
txt: &str,
sess: &Session,
vars: Variables,
strict: bool,
) -> Result<Vec<Response>, Error> {
// Call middleware if implemented, continue or break with error
// I don't know if this is a good spot to do this here.
// I'm not that familiar with the code-base yet
--------> try_middleware(txt, sess, vars)?;
/... /
// Process all statements
exe.execute(ctx, opt, ast).await
}
—
Reply to this email directly, view it on GitHub
<#111 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJZZE2R5AAFHCFQEKTMJHCDV5H2PLANCNFSM6AAAAAAQHWAYEU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I think it would be useful to have an, optional, middleware function. In embedded use external code, rust or webassembly maybe, could implement it and have access to session, parsed query and all other call data just before query is executed. And have ability to break the query execution, optionally, providing custom error response. So, basically, external code could tap into the db query exec.
Beta Was this translation helpful? Give feedback.
All reactions