-
Notifications
You must be signed in to change notification settings - Fork 4
Accessing databases
The Hot framework makes database access easy. Each show exposes a show.db object if a database is defined in the project.
Accessing multiple databases in the same project is supported. If multiple databases are defined, a show.db map is provided in each show, each map entry targeting a previously defined database.
Hot framework actually supports some relational databases and mongodb databases
The following relational databases are currently supported:
- Mysql and all its flavours
- Postgresql
- Oracle DB
- DB2
- HSQLDB
In order to add a datasource to your project, just use the hotcommand line tool
$ hot <dbtype> -n <db_identifier> where dbtype is one of the above RDBM's and db_identifier is a unique key that identify the datasource in your project
CLI usage:
hot mysql -n <datasource_name> -db database -u username [-h host]
[-port port] [-p password]
-db,--database <arg> DB to connect to
-h,--host <arg> Hostname or IP address of DB server (default:
localhost)
-n,--name <arg> Name of the datasource
-p,--password <arg> password used for DB connection (default: empty)
-port,--port <arg> connection port of DB server (default: 3306)
-u,--username <arg> username used for DB connection$ hot mysql -n db_mysql -db petclinic -u dsolimandowill add a datasource named db_mysql targeting a localhost mysql server. The datasource will connect to the petclinic database. Connections will be done with the dsolimando mysql user.
$ hot mysql -n db_mysql -db petclinic -u dsolimando -p toto -h mysql1.hot.be -port 6612will add a datasource named db_mysql targeting the remote mysql1.hot.be mysql server on the 6612 TCP port. The datasource will connect to the petclinic database and connections will be done with the dsolimando mysql user and the toto password.
CLI usage
hot pgsql -n <datasource_name> -db database -u username [-h host]
[-port port] [-s schema] [-p password]
-db,--database <arg> DB to connect to
-h,--host <arg> Hostname or IP address of DB server (default:
localhost)
-n,--name <arg> Name of the datasource
-p,--password <arg> password used for DB connection (default: empty)
-port,--port <arg> connection port of DB server (default: 5432)
-s,--schema <arg> Schema to be set in the search-path
-u,--username <arg> username used for DB connection$ hot pgsql -n pg1 -db petclinic -u dsolimandowill add a datasource named pg1 targeting a localhost postgresql server. The datasource will connect to the petclinic database. Connections will be done with the dsolimando mysql user.
$ hot pgsql -n pg2 -db petclinic -u dsolimando -p toto -h pg2.hot.be -port 9864will add a datasource named pg2 targeting the remote pg2.hot.be postgresql server on the 9864 TCP port. The datasource will connect to the petclinic database and connections will be done with the dsolimando user and toto password.
$ hot pgsql -n pg2 -db petclinic -u dsolimando -p toto -h pg2.hot.be -port 9864 -schema sch1Same as previous command but scoping statements to the sch1 database schema
CLI usage
hot oracle -n <datasource_name> -u username -sid service -p
password [-h host] [-port port] [-s schema]
-h,--host <arg> Hostname or IP address of DB server (default:
localhost)
-n,--name <arg> Name of the datasource
-p,--password <arg> password used for DB connection (default: empty)
-port,--port <arg> connection port of DB server (default: 1521)
-s,--schema <arg> DB schema to connect to
-sid,--service <arg> Oracle service name or SID
-u,--username <arg> username used for DB connection
$ hot oracle -n or1 -u dsolimando -p toto -sid petshop -h or1.hot.be -schema sch1will add a datasource named or1 targeting the remote or1.hot.be oracle server. The datasource will connect to the petshop instance and statements will be scoped to to the sch1 database schema. Connections will be done with the dsolimando user and toto password.
In order to use the oracle datasource, you'll need to add the driver jar in the /lib folder at the root of your project.
CLI usage
hot db2 -n <datasource_name> -db database -u username [-h host]
[-port port] [-s schema] [-p password]
-db,--database <arg> DB to connect to
-h,--host <arg> Hostname or IP address of DB server (default:
localhost)
-n,--name <arg> Name of the datasource
-p,--password <arg> password used for DB connection (default: empty)
-port,--port <arg> connection port of DB server (default: 50000)
-s,--schema <arg> DB schema to connect to
-u,--username <arg> username used for DB connection$ hot db2 -n ibm1 -db petshop -u dsolimandowill add a datasource named ibm1 targeting a localhost db2 server. The datasource will connect to the petclinic database. Connections will be done with the dsolimando user.
$ hot db2 -n ibm1 -db petshop -u dsolimando -p toto -h db2.hot.be -port 25000 -schema sch1will add a datasource named ibm1 targeting the remote db2.hot.be db2 server instance. The datasource will connect to the petshop database and statements will be scoped to the sch1 database schema. Connections will be done with the dsolimando user and toto password.
In order to use the db2 datasource, you'll need to add the driver jar in the /lib folder at the root of your project.
CLI usage
hot hsqldb -n <datasource_name> -db database [-s schema] [-u
username] [-p password]$ hot hsqldb -n hsqldb1 -db petclinicwill add a datasource named hsqldb1 connecting to the petclinic database.
CLI usage
hot mongo -n <datasource_name> –db database [-h host] [-port port]
[-u username] [-p password]
-db,--database <arg> DB to connect to
-h,--host <arg> Hostname or IP address of MongoDB server (default:
localhost)
-n,--name <arg> Name of the datasource
-p,--password <arg> password used for DB connection (default: empty)
-port,--port <arg> connection port of MongoDB server (default: 27017)
-u,--username <arg> username used for DB connection$ hot mongo -n m1 -db petclinicwill add a datasource named m1 targeting a localhost mongodb server. The datasource will connect to the petclinic database.
In order to remove a datasource of your project, use the following command
$ hot rmdb -n <db_identifier> where db_identifier is the unique key that identify the datasource in your project