That should work. The only time it wouldn’t is if the database is very large or your internet connection is slow. It works because the database loads faster than a person clicking. That is fine, no one will notice.
If you are interested in making it fool proof continue reading:
Try this. Open your project. Reload it. (Database is cached.) Run it. Disconnect your internet. Click the first button. Click the second button. You get an error.
The reason for that is there is still nothing to keep the user from clicking on the second button before the database has finished loading. To avoid that we need some way to wait till the database is loaded before we press that second button. We can do that by hiding it and only showing it after the database is loaded. Look at this:
What I have done is put
showElement("button2"); into the database callback. If I then make that button hidden to start with it will show up after the database is done loading. I put 5000 records into the database so you see it pop up after a second.
You can unhide the button, reload, run and click the buttons fast. You will get an error. Again, because it hasn’t finished loading. (Mostly it is filling the Array that takes all the time. Directly using the Array and JSON objects that are returned is faster.)
Here is another thread that looks at App Lab databases and faulty connections Does update/read/createRecord return an error where there's a timeout?