Fix importing from 1.x (#4725)

Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
Micha de Vries 2024-09-10 14:14:01 +01:00 committed by GitHub
parent 516bb977ac
commit 714bf9ebc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -257,11 +257,17 @@ impl<'a> Executor<'a> {
}
// Begin a new transaction
Statement::Begin(_) => {
if opt.import {
continue;
}
self.begin(Write).await;
continue;
}
// Cancel a running transaction
Statement::Cancel(_) => {
if opt.import {
continue;
}
self.cancel(true).await;
self.clear(&ctx, recv.clone()).await;
buf = buf.into_iter().map(|v| self.buf_cancel(v)).collect();
@ -272,6 +278,9 @@ impl<'a> Executor<'a> {
}
// Commit a running transaction
Statement::Commit(_) => {
if opt.import {
continue;
}
let commit_error = self.commit(true).await.err();
buf = buf.into_iter().map(|v| self.buf_commit(v, &commit_error)).collect();
self.flush(&ctx, recv.clone()).await;

View file

@ -156,7 +156,23 @@ impl Statement {
opt: &Options,
doc: Option<&CursorDoc>,
) -> Result<Value, Error> {
match self {
let stm = match (opt.import, self) {
// All exports in SurrealDB 1.x are done with `UPDATE`, but
// because `UPDATE` works different in SurrealDB 2.x, we need
// to convert these statements into `UPSERT` statements.
(true, Self::Update(stm)) => &Statement::Upsert(UpsertStatement {
only: stm.only,
what: stm.what.to_owned(),
data: stm.data.to_owned(),
cond: stm.cond.to_owned(),
output: stm.output.to_owned(),
timeout: stm.timeout.to_owned(),
parallel: stm.parallel,
}),
(_, stm) => stm,
};
match stm {
Self::Access(v) => v.compute(ctx, opt, doc).await,
Self::Alter(v) => v.compute(stk, ctx, opt, doc).await,
Self::Analyze(v) => v.compute(ctx, opt, doc).await,