mysql - Multiple database connections in Rails -


I am writing a simple version of phpMyAdmin in Rail; This web app will be run on a web server (where the user will be able to point to the database name, hostname, user name, password, and port number of database servers running on the same network). The user will then be connected to that machine and will be able to use the UI to manage that database (add or remove columns, drop tables, etc.).

I have two related questions (your help too)

  1. In a traditional rail application, I store the database information in database.yml, though here I Need to do it dynamically. Is the database .iml file a good way to free up the file and tell the train to access the connection data available at the run-time by the user?

  2. Individual users should be connected separately Databases (or even hosts). I think I need to keep track of the connection between an established database connection and a user session.

    1. To prevent the railway from launching ActiveRecord using database.yml, you You can delete : active_record in the config.frameworks config /environment.rb. Thereafter, to establish the connection manually, you can ActiveRecord :: Base .establish_connecti On . (And maybe ActiveRecord :: base.configurations )

      ActiveRecord stores all the connections related to class variables so if If you want to dynamically create more than one connection, then you also have dynamic ActiveRecord: subclass and call establ_connection on it.

      Your abstract base class will be the table for any subclass used to actually manage it. In order to know about ActiveRecord, you should do the definition of self.abstract_class = true base class.

      Then, each table that you want to manage will dynamically change this new sub-class.

    2. It is more difficult because you can not really release the connection, of course. I can imagine that the instant solution is accumulating a unique token in session, and uses it to go back to a dynamic ActiveRecord :: Base subclass beforehand, which you probably will store in a hash.

      • You will have to store all database connection information in the session, so other workers can use it.

        Li>
      • You probably want a similar unique token between all workers, so use a hash function on the combination of database connection parameters.
      • Because a worker can be called with token, it is not yet known, your sub-closing and installation_connection argument will probably be in the first_filter (for example, rather than the entry moment .)
      • User must collect garbage connections and find some clever methods of classes, when the user does not log out properly and the session ends (Sorry, I do not know this.)

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -