compass-db icon indicating copy to clipboard operation
compass-db copied to clipboard

Split the write step in two

Open cwackerfuss-rl opened this issue 7 years ago • 1 comments

Just want to bring this up as a discussion:

In some situations, the user may want to make several changes to their data before committing them to the database.

For example, imagine a post which has an array of category IDs. If the user decides to create a new category while creating a new post, a developer might decide to put these two requests in a submit function. If the category creation request fails BUT the post creation succeeds with a reference to a non-existent category, our data integrity is compromised.

In Rails, SQLAlchemy, and others, they solve this issue by storing a working copy of the DB in session. In SQLAlchemy pseudocode, this looks like...

db.session.add('thing')
db.session.remove('something else')
... perform other operations
db.session.commit()

In addition to abstracting data integrity management to Compass, this also cuts down on the number of requests the user is making.

Of course, this is made slightly more difficult since it's happening on the client... but I'm curious to hear you guys' thoughts.

cwackerfuss-rl avatar Jan 04 '18 19:01 cwackerfuss-rl

I really like this idea, however I think it should be optional (I know this is a lot more work! :P). 2 phase commit for DBs is generally an advanced feature, but offered:

jackzampolin avatar Jan 04 '18 20:01 jackzampolin