What is the best way to handle multiple SQLite tables

I am working on a sample app to learn ionic, the app deals with multiple SQLite tables of a single DB. I have a database service which creates the DB, tables and also inserts some initial data.

I followed a tutorial example which used a single database service to execute SQL operation on a single table. Using single service for multiple tables may mess things up and also for sure is not a best practice. So I was wondering, what is the best way to initialise the DB/tables and handle multiple tables? Is it recommended to use multiple services i.e. one for each object/table?

You seem to have already made you mind up about the question you’re asking, so I doubt you’ll like this answer, but I would personally have zero problem with one service fronting for data coming from multiple database tables.

I do, however, wonder if your sample application is going to be representative of real-world development. Such a complex data structure that requires actual SQL is rarely best done on-device, but rather on a networked backend server. I would consider architecting the app so that the data access could at least be done via HTTP and REST instead of SQLite.

1 Like

@rapropos Thanks for your comment. Actually, this app requires offline storage, which may later require to send and sync to a server just for backup (in future in case of real world deploy).

I am planning to structure the app in a way that If later I want to deploy it then I won’t have to change or rework on the existing functionality but just extend or add the functionality.

There will not be any complex queries as we have mostly CRUD operations. There are about 7-8 different tables. I was thinking if we can have a single DB connection and use it in different data model classes (services), but I couldn’t figure it out last night.

I appreciate your reply and thanks for the suggestion.