Can I delete and insert in same transaction?

92 views
Skip to first unread message

nysource

unread,
Jul 31, 2020, 5:13:27 AM7/31/20
to lovefield-users
Hello.
I want to insert row(s) after delete rows in one transaction.
But I can't get expected result.
Below example runs without any error.
But when reload web page or (db.close() and schemaBuilder.connect()), "items" table's result alternates 1 row(expected) and empty at each running.

var item = db.getSchema().table('items');
var transaction = db.createTransaction();
transaction.begin(item).then(function() {
 
var query = db.delete().from(item);
 
return transaction.attach(query);

})
.then(function(result) {
 
var query = db.insert().into(item).values(item.createRow({
    code
: 1,
    name: 'Banana'
 
}));
 
return transaction.attach(query);
}).then(function(result) {
 
return transaction.commit();
}).then(function() {
  return db.select().from(item).exec();
}).then(function(result) {
  console.log(result); // geting every 1 row(correct)
});

--- Reload page or (db.close() and schemaBuilder.connect()) ---

var item = db.getSchema().table('items');
db.select().from(item).exec().then(function(result) {
  console.log(result); // alternated 1 row
(correct) and empty(incorrect).
});

Could you give me any ideas?

Thanks.

Arthur Hsu

unread,
Jul 31, 2020, 1:30:38 PM7/31/20
to lovefield-users
If you connect to an in-memory database, then the results will not persist across connections. Please verify if that's the case.
If not, we need a minimal repro and browser version to tell what's going on.

yoichi_...@gcom-grp.co.jp

unread,
Aug 2, 2020, 11:37:21 PM8/2/20
to lovefield-users
Thank you for your reply.
I connect to an IndexedDB.
I create minimal repro below.
I test this on Chrome(84.0.4147.105/Windows) and Firefox(79.0/Windows).

Thanks.

Arthur Hsu:

Arthur Hsu

unread,
Aug 3, 2020, 1:34:48 PM8/3/20
to lovefield-users
Filed https://github.com/google/lovefield/issues/264 and let's move the discussions there.

nysource

unread,
Aug 3, 2020, 9:52:06 PM8/3/20
to lovefield-users
OK.
I'll check it out.
Thanks for the great product and your support.

2020年8月4日火曜日 2時34分48秒 UTC+9 Arthur Hsu:
Filed https://github.com/google/lovefield/issues/264 and let's move the discussions there.
Reply all
Reply to author
Forward
0 new messages