Skip to content

How to use mysql with Conjure

mattloidolt edited this page Jun 8, 2012 · 4 revisions

Added for version: 0.4

Conjure currently supports only two different databases, h2 and mysql. By default, Conjure uses h2 as an embedded database, and is preconfigured to use it.

Db_config.clj

If you want to change to mysql, you must update the db_config.clj file in your config directory.

Before we can update db_config.clj we need to know how Conjure interfaces with a database. Since all database syntax are different Conjure must have an interface it can use to do all of it’s operations. The database interface Conjure uses is called a flavor and they can be found in the db/flavors directory. Since Conjure currently only supports h2 and mysql, there are only h2 and mysql flavors in the directory. As more databases are supported, more flavors will be added.

In db_config.clj, all we have to do is load the correct flavor and put it where Conjure can use it.

To load the flavor, simply require it. Change the following line:

  (:require [flavors.h2 :as h2]

To:

  (:require [flavors.mysql :as mysql]

Now we need to put it where Conjure can use it. Update the line:

:flavor (h2/flavor)

To:

:flavor (mysql/flavor)

Now you’re done. Mysql will be used instead of h2. However, you may want to update the username, password and database names in db_config.clj to the values in your mysql database.

Setting Mysql At Creation Time

When you create a conjure app, you can pass the “-database” option to set the database.

Using the stand alone jar, to set the database to mysql and a new project called mysql_project use:

java -jar conjure.jar -database mysql mysql_project

Using the Leiningen plugin, to set the database to mysql use:

lein conjure new --database mysql

The db_config file will be automatically updated to use mysql. You’ll need to go into db_config.clj to set your username, password, and database names to complete the setup.

Clone this wiki locally