Refactor - reduce redundancy in Datastore::execute. (#2095)

This commit is contained in:
Finn Bear 2023-06-19 15:35:08 -07:00 committed by GitHub
parent e389e51b7f
commit 2019290a0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -298,33 +298,10 @@ impl Datastore {
vars: Variables, vars: Variables,
strict: bool, strict: bool,
) -> Result<Vec<Response>, Error> { ) -> Result<Vec<Response>, Error> {
// Create a new query options
let mut opt = Options::default();
// Create a new query executor
let mut exe = Executor::new(self);
// Create a default context
let mut ctx = Context::default();
// Set the global query timeout
if let Some(timeout) = self.query_timeout {
ctx.add_timeout(timeout);
}
// Start an execution context
let ctx = sess.context(ctx);
// Store the query variables
let ctx = vars.attach(ctx)?;
// Parse the SQL query text // Parse the SQL query text
let ast = sql::parse(txt)?; let ast = sql::parse(txt)?;
// Setup the auth options // Process the AST
opt.auth = sess.au.clone(); self.process(ast, sess, vars, strict).await
// Setup the live options
opt.live = sess.rt;
// Set current NS and DB
opt.ns = sess.ns();
opt.db = sess.db();
// Set strict config
opt.strict = strict;
// Process all statements
exe.execute(ctx, opt, ast).await
} }
/// Execute a pre-parsed SQL query /// Execute a pre-parsed SQL query