2 Replies Latest reply on Jul 17, 2015 4:04 AM by Krishna Raja

    Check if table / model exists in local database - isTableExist(STRING tableName)

    Joerg Koch

      Hi all,


      the initial startup up my app is pretty slow, since I'm seeding a large products table and that's OK. Yet, on the subsequent starts of the app, the startup should be fast.


      I wonder what might be the fastest way to check if a table / model already exists.


      I tested:


      products = Product.find(:all)
      if products.empty?


      which is of course pretty slow (nearly the same speed as the initial seed...).


      product = Product.find(:first)
      if product


      does not accelerate much.


      if Product.count == 0

      is much faster. Still, is there a better way?

      I experimented with http://docs.rhomobile.com/en/5.1.1/api/Database#misTableExist:

      db = new Rho::Database(Rho::Application.databaseFilePath("local"), "local")

      yet, it always returns false and the "new Rho::Database" documentation states "Do not use predefined partition names: app, user, local".

      Which is the best way to check if a table exists in the local database?

      Thanks in advance for any hints!