Recommended way to interact with db from Composer

I have an app with multiple Composer scenes where I need to have all of them get data from the same database. The application is fairly complex so I wanted to get some advice before I make a mess.

Maybe I don’t understand the scope of Composer. Is it a virtual environment like a coroutine or is it a display group with some extra methods?

If it is the former, I’m not going to be able to access anything outside of the envelope of the scene. If it is the latter then I just need to make the db a global and then just access it wherever I need it.

Also, is there going to be a problem leaving the runtime listener for onSystemEvent in main.lua?

Any advice?

All of the below is about the ‘Composer Scene Management Library/Module’ NOT the same-named editor.

Short answer to your question: More of the latter.

Composer doesn’t affect your ability to see:

  • globals
  • modules
  • anything really…

My advice:

  1. Create a DB module.
  2. Require the module in main.lua and do any init calls you need there
  3. Require that module in any scene that needs access to the data and use your own module methods to access the data.

This will be clean and organized.

Tip: One question per post if you want an answer to each unique question (unless the questions are all related or dependent upon prior answers).  I almost missed the second question…

No, there is no problem ‘leaving the runtime listener for onSystemEvent in main.lua

However, I’d try to avoid cluttering main.lua with functional code if you can avoid it.  i.e. Use a module instead to separate functional code.

Ok, I can do that. Thank you.

All of the below is about the ‘Composer Scene Management Library/Module’ NOT the same-named editor.

Short answer to your question: More of the latter.

Composer doesn’t affect your ability to see:

  • globals
  • modules
  • anything really…

My advice:

  1. Create a DB module.
  2. Require the module in main.lua and do any init calls you need there
  3. Require that module in any scene that needs access to the data and use your own module methods to access the data.

This will be clean and organized.

Tip: One question per post if you want an answer to each unique question (unless the questions are all related or dependent upon prior answers).  I almost missed the second question…

No, there is no problem ‘leaving the runtime listener for onSystemEvent in main.lua

However, I’d try to avoid cluttering main.lua with functional code if you can avoid it.  i.e. Use a module instead to separate functional code.

Ok, I can do that. Thank you.