Fix importing from 1.x (#4725)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
516bb977ac
commit
714bf9ebc5
2 changed files with 26 additions and 1 deletions
|
@ -257,11 +257,17 @@ impl<'a> Executor<'a> {
|
||||||
}
|
}
|
||||||
// Begin a new transaction
|
// Begin a new transaction
|
||||||
Statement::Begin(_) => {
|
Statement::Begin(_) => {
|
||||||
|
if opt.import {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
self.begin(Write).await;
|
self.begin(Write).await;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Cancel a running transaction
|
// Cancel a running transaction
|
||||||
Statement::Cancel(_) => {
|
Statement::Cancel(_) => {
|
||||||
|
if opt.import {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
self.cancel(true).await;
|
self.cancel(true).await;
|
||||||
self.clear(&ctx, recv.clone()).await;
|
self.clear(&ctx, recv.clone()).await;
|
||||||
buf = buf.into_iter().map(|v| self.buf_cancel(v)).collect();
|
buf = buf.into_iter().map(|v| self.buf_cancel(v)).collect();
|
||||||
|
@ -272,6 +278,9 @@ impl<'a> Executor<'a> {
|
||||||
}
|
}
|
||||||
// Commit a running transaction
|
// Commit a running transaction
|
||||||
Statement::Commit(_) => {
|
Statement::Commit(_) => {
|
||||||
|
if opt.import {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let commit_error = self.commit(true).await.err();
|
let commit_error = self.commit(true).await.err();
|
||||||
buf = buf.into_iter().map(|v| self.buf_commit(v, &commit_error)).collect();
|
buf = buf.into_iter().map(|v| self.buf_commit(v, &commit_error)).collect();
|
||||||
self.flush(&ctx, recv.clone()).await;
|
self.flush(&ctx, recv.clone()).await;
|
||||||
|
|
|
@ -156,7 +156,23 @@ impl Statement {
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
doc: Option<&CursorDoc>,
|
doc: Option<&CursorDoc>,
|
||||||
) -> Result<Value, Error> {
|
) -> 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::Access(v) => v.compute(ctx, opt, doc).await,
|
||||||
Self::Alter(v) => v.compute(stk, ctx, opt, doc).await,
|
Self::Alter(v) => v.compute(stk, ctx, opt, doc).await,
|
||||||
Self::Analyze(v) => v.compute(ctx, opt, doc).await,
|
Self::Analyze(v) => v.compute(ctx, opt, doc).await,
|
||||||
|
|
Loading…
Reference in a new issue