next up previous index
Next: flt_storage Up: Data Storage Previous: csv_storage and tab_storage   Index


sql_storage

The constructor of this class expects an entry storage_location in its arguments. This parameter should be an OpusDatabase and it governs a connection to a database. Here's an example of obtaining an OpusDatabase and then creating a storage object that can read and write from that database:

>>> import os
>>> from opus_core.database_management.database_server_configuration import \
                                         DatabaseServerConfiguration
>>> from opus_core.database_management.database_server import DatabaseServer
>>> from opus_core.storage_factory import StorageFactory
>>> config = DatabaseServerConfiguration(hostname = 'my.host.net',
                                         username = 'me',
                                         password = 'my_password',
                                         protocol = "mysql")
>>> db_server = DatabaseServer(config)
>>> db = db_server.get_database(database_name = ``mydatabase'')
>>> storage = StorageFactory().get_storage('sql', storage_location = db)

Note that you should probably never have to create a DatabaseServerConfiguration object directly - instead, you should instantiate the child classes of EstimationDatabaseConfiguration, IndicatorsDatabaseConfiguration, ServicesDatabaseConfiguration, or ScenarioDatabaseConfiguration. Configurations of these types will default to the server information found in ``[OPUS_HOME]/settings/database_server_configuration.xml''.

Now you have obtained a sql_storage object. For this storage class, all implemented methods of the storage interface which accept a table_name parameter interpret it as name of a table in the database which is to be read from or written to, depending on the method.


next up previous index
Next: flt_storage Up: Data Storage Previous: csv_storage and tab_storage   Index
info (at) urbansim.org