Neptune 1.0 Beta 3 Documentation: Using the Database

Neptune Information

Download from RIA Forge

Using the Database

Based on Dan Wilson's "So you want to build a ModelGlue:Unity application" (and the CFWheels version of same), this page encompasses the following steps:

Now that we have a working prototype, we want to hook it up to a database and try it out.

Database and Datasource

First create a database and a datasource to point to it (named "ContactOMatic" for this example). Make sure your datasource has permissions for both "CREATE" and "ALTER" statements.

Change your datasource configuration (in _config/config.cfm) to the database you set up (otherwise the site will run on the simulated database, which is good for prototyping but doesn't actually save data).


More about configuring setting

The base component that uses the datasource setting is DataMgr, so refresh DataMgr (anything that uses DataMgr - directly or indirectly - will also be refreshed) or if you don't want to remember what to refresh you can just do a refresh=true to refresh everything.

Now Contact-O-Matic is running against a live database!

What Happened?

<table entity="Contact Type">
	<field name="ContactTypeName" Label="Type" type="text" Length="20" required="true" />
<table entity="Contact">
	<field fentity="Contact Type" />

Based on the XML table definitions, the component will create the tables (if your datasource has "CREATE" permissions) and columns (if your datasource has "ALTER" permissions) that don't exist in the database already.

	<row ContactTypeName="Friend" />
	<row ContactTypeName="Co-Worker" />
	<row ContactTypeName="Enemy" />

Based on the XML data definitions, these rows will be created in this table when the table is created. Adding a permanentRows="true" to the "data" element will have the code ensure that the rows exist even if the table was previously created.

Adding a Record

Now the list page doesn't have any records since we don't have any contacts loaded, so click "Add Contact" and create one. You will see that it should work just as you expect.

Editing a Record

You can now click the "edit" link for a record and see the data that you added. Change the values and submit form and your changes will save.

Removing a Record

You can remove a record by clicking the "Delete" button on the list page or on the edit form. All done!

Next: Images and Files