Is there is a way in the platform to know if an object is LocalDB or OnlineDB?
Yes, you can do this as follows:
object._adapter.description() === LocalDB
object is the name of your database object.
Please note that is an internal API and might change without warning in future.