Generate a data source configuration file for Persevere from a MySQL database.
JavaScript Shell
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


persevere-mysql-autoconfig version 0.1b
August 1st, 2008
by Eric Abouaf <eric.abouaf at>

	Generate a data source configuration file for Persevere from a MySQL database. 

	* Create the folder /path/to/persevere/tools and unzip into it
		(The script has references to file relative to this path.)
   * Move the mysql-connector-java-5.1.6-bin.jar file into /path/to/persevere/lib/
		(This allow Persevere to connect to the mysql database)

	* Edit the configuration section in persevere-mysql-autoconfig.js
	* Run the script: /bin/sh
		=> generates a "myDatabase.json" file with all tables 
	* Edit the generated file: (all of these are optional)
		- Change the model name (don't forget to change the data.$ref accordingly)
		- Edit the idColumn
		- add javascript functions to the class or its prototype. (don't forget to set the @runAt variable)
		- add relationships between models (look at)
	* copy the myDatabase.json file into /path/to/persevere/WEB-INF/config
	* (re)start persevere "java -jar start.jar"
	* use the REST api to check that everything works !
		- for a model "myModel" (default is the database table name), 
		  go to http://localhost:8080/myModel or http://localhost:8080/myModel/ or http://localhost:8080/myModel/1


	* Error handling is very poor
	* This apparently can't be done with gen-server created app servers, and you really need to
          do java -jar start.jar in the persevere directory.
	  (I suspect this is a java classpath issue).


* id column should be called "id" and must be primary key
create table myTable(id int not null auto_increment, primary key(id), firstname varchar(30), lastname varchar(30));

$ curl localhost:8080/myTable
$ curl -d '{firstname:"ray", lastname:"medeiros"}' localhost:8080/myTable
$ curl localhost:8080/myTable