Class DatabaseConnector
source code
A DatabaseConnector provides simple read access to a SQL database.
On initialisation it connects to a given database. Once connected it's
select methods can be used to quickly access the database content.
DatabaseConnector supports a wide range of database systems through
SQLalchemy.
As only standard select commands are issued further systems should be
easy to incorporate.
For selecting entries there are for different methods given:
-
selectRows()
: the most general select method
-
selectScalars()
: returns entries for only one column
-
selectRow()
: returns only one entry
-
selectScalar()
: returns one single value
|
__init__(self,
databaseUrl)
Constructs the DatabaseConnector object and connects to the database
specified by the options given in databaseSettings. |
source code
|
|
|
_registerViews(self)
Registers all views and makes them accessible through the same
methods as tables in SQLalchemy. |
source code
|
|
|
execute(self,
*options,
**keywords)
Executes a request on the given database. |
source code
|
|
|
|
|
|
|
|
|
|
|
dbconnectInst = None
Instance of a DatabaseConnector used for all connections to SQL
server.
|
|
databaseUrl = None
Database url used to create the connector instance.
|
getConfigSettings(projectName)
Static Method
| source code
|
Gets the SQL connection parameter from a config file.
- Parameters:
projectName (str) - name of project which will be used as name of the config file
- Returns: dict
- configuration settings for the given project
|
Constructs the DatabaseConnector object and connects to the database
specified by the options given in databaseSettings.
- Parameters:
databaseUrl (str) - database connection setting in the format
driver://user:pass@host/database .
|
Registers all views and makes them accessible through the same methods
as tables in SQLalchemy.
Attention:
Currently only works for MySQL and SQLite.
|
Executes a select query and returns a single variable.
- Parameters:
- Returns:
- a scalar
|
Executes a select query and returns a list of scalars.
- Parameters:
- Returns:
- a list of scalars
|
Executes a select query and returns a single table row.
- Parameters:
- Returns:
- a list of scalars
|
Executes a select query and returns a list of table rows.
- Parameters:
- Returns:
- a list of scalars
|