Below is a simple example of the steps for setting up a simple database driven application using Fins. Commands that should be typed are listed in bold. 1. Download Fins, unpack and change into the Fins directory.
hera:/tmp hww3$ curl -o Fins.zip http://hww3.riverweb.com/dist/Fins/Fins-0.2.zip % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 760k 100 760k 0 0 83665 0 0:00:09 0:00:09::-- 98487 hera:/tmp hww3$ unzip Fins.zip Archive: Fins.zip hera:/tmp hww3$ cd Fins-0.2/
hera:/tmp/Fins-0.2 hww3$ pike -Mlib -x fins create widgetco /18:35:17 INFO - CreateApplication module loading 18:35:17 INFO - CreateApplication module running. 18:35:17 INFO - Creating application widgetco in /private/tmp/Fins-0.2. 18:35:17 INFO - Be sure to edit config/*.cfg to specify the application's datasource
hera:/tmp/Fins-0.2 hww3$ mysqladmin -p create -uroot foo Enter password: hera:/tmp/Fins-0.2 hww3$ mysql -uroot foo -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 18 to server version: 5.0.27-standard Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> grant all on foo.* to foo identified by 'foo4u'; Query OK, 0 rows affected (0.01 sec)
mysql> create table widgets( id int(11) not null auto_increment primary key, name char(32), on_hand int(11) , manufacturer_id int(11)); Query OK, 0 rows affected (0.00 sec) mysql> create table manufacturers( id int(11) not null auto_increment primary key, name char(32), phone_number char(16) ); Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
hera:/tmp/Fins-0.2 hww3$ vi widgetco/config/dev.cfg
hera:/tmp/Fins-0.2 hww3$ cd widgetco hera:/tmp/Fins-0.2/widgetco hww3$ export FINS_HOME=/tmp/Fins-0.2
hera:/tmp/Fins-0.2/widgetco hww3$ bin/start.sh 18:43:08 INFO - FinServe starting on port 8080 18:43:08 INFO - Starting Session Manager. 18:43:08 INFO - FinServe loading application widgetco using configuration dev 18:43:08 INFO - Starting Cache. 18:43:08 INFO - loading model from model 18:43:08 INFO - Application widgetco loaded. 18:43:08 INFO - Application ready for business. <CTRL-C> hera:/tmp/Fins-0.2/widgetco hww3$
hera:/tmp/Fins-0.2/widgetco hww3$ bin/fins.sh model add manufacturers widgets
hera:/tmp/Fins-0.2/widgetco hww3$ bin/start.sh --hilfe
18:52:33 INFO - Application widgetco loaded.
Starting interactive interpreter...
Fins 0.4 running Pike v7.8 release 352 / Hilfe v3.5 (Incremental Pike Frontend)
> object m = widgetco.Objects.Manufacturer();
> m["name"] = "Spacely Sprockets";
(2) Result: "Spacely Sprockets"
> m->save();
(3) Result: 0
> object m = widgetco.Objects.Manufacturer();
> m["name"] = "Cogswell Cogs";
(4) Result: "Cogswell Cogs"
> __m->save();
(5) Result: 0
> object w = widgetco.Objects.Widget();
> w["name"] = "SuperCog 2000";
(6) Result: "SuperCog 2000"
> w["Manufacturer"] = m;
(7) Result: Manufacturer(id=2)
> w["on_hand"] = 12;
(8) Result: 12
> w->save();
(9) Result: 0
> indices(w);
(10) Result: ({ /* 4 elements */
"on_hand",
"Manufacturer",
"name",
"id"
})
> w["Manufacturer"];
(1) Result: Manufacturer(id=2/2)
> w["Manufactuer"]["name"];
(11) Result: "Cogswell Cogs"
hera:/tmp/Fins-0.2/widgetco hww3$ vi modules/widgetco.pmod/DataMappings.pmod/Manufacturer.pike
void post_define() { set_alternate_key("name"); }
hera:/tmp/Fins-0.2/widgetco hww3$ bin/start.sh --hilfe
20:24:22 INFO - FinServe starting on port 8080
...
Starting interactive interpreter...
Fins 0.4 running Pike v7.8 release 352/ Hilfe v3.5 (Incremental Pike Frontend)
> Fins.Model.find.manufacturers_by_id(1);
(1) Result: Manufacturer(name=Spacely Sprockets)
> Fins.Model.find.manufacturers_by_alternate("Cogswell Cogs");
(4) Result: Manufacturer(name=Cogswell Cogs)
// our simple phone number regexp.
constant pnf = "[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]";
void validate(mapping changes, object errors, object i)
{
if(changes->phone_number)
{
object r = Regexp.SimpleRegexp(pnf);
if(!r->match(changes->phone_number)) // if we're not a valid phone number, complain.
errors->add("phone_number", "must be in the format nnn-nnn-nnnn.");
}
}
hera:/tmp/Fins-0.2/widgetco hww3$ bin/start.sh --hilfe
20:24:22 INFO - FinServe starting on port 8080
...
Starting interactive interpreter...
Fins 0.4 running Pike v7.8 release 352 / Hilfe v3.5 (Incremental Pike Frontend)
> object m = Fins.Model.find.manufacturers_by_id(1);
(1) Result: Manufacturer(name=Spacely Sprockets)
> m["phone_number"] = "8885551212";
Data Validation Error
Phone number must be in the format nnn-nnn-nnnn.
lib/Fins.pmod/Model.pmod/DataObject.pike:664:
wooga.Model.Manufacturer()->set("phone_number","1234567890",UNDEFINED,Manufac
turer(name=Spacely Sprockets))
lib/Fins.pmod/Model.pmod/DataObjectInstance.pike:223:
Manufacturer(name=Spacely Sprockets)->`[]=("phone_number","1234567890")
>
object manufacturers;
object widgets;
void start()
{
manufacturers = load_controller("mfg_controller");
widgets = load_controller("widget_controller");
}
inherit Fins.ScaffoldController; // What data type shall we build an editor scaffolding for? string model_component = "Manufacturer";
inherit Fins.ScaffoldController; // What data type shall we build an editor scaffolding for? string model_component = "Widget";