Not a big deal in Orchid. If u have a table named “users” in your mysql database with the following structure, you can interact with it like this.
CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(250) DEFAULT NULL, `password` varchar(32) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM
Here is how to interact using a model
$usersmodel = $this->model->users; $usersmodel->username = "test"; $usersmodel->password = "testpass"; $usersmodel->insert(); $usersmodel->find("username = 'test'"); $usersmodel->username = "tester"; $usersmodel->update();
You dont need to write any code for this model “users”. It is auto generated using the active record library that comes with orchid. You can generate models by naming them same as table names in your database. Easy, huh?
6 Responses
Jon Gilkison
December 25th, 2007 at 9:16 am
1Do you cache the model or do you do a lookup everytime to figure out the column names/types?
How do you support schemas in postgresql?
Masud
December 25th, 2007 at 4:03 pm
2Hasin vai, it sounds great. I would like to know something. Can u do something like that, which will analysis a query and then inform whether the query needs to be optimize or not. this info will be shown when we would debug a specific query.
i don’t know whether it is efficient or not. but i would like to know about this.
looking forward to hear something from you.
thanks
Masud
Hasin Hayder
December 25th, 2007 at 4:46 pm
3Jon, Thanks for informing this. This part is still under progress. And yeah, we were fetching model info every time.
I am going to cache it. You will get the update as soon as I am done.
and about PGSQL, it is like this
SELECT column_name FROM information_schema.columns WHERE table_name = table_name
Hasin Hayder
December 25th, 2007 at 4:46 pm
4@Masud - I will keep that in mind and try to give u some update ASAP.
Victor
December 26th, 2007 at 11:39 am
5Hasin Hayder, can you tell me more about tables relations? Will it be possible to do Rails-like ‘chains’? For example, we have your table user with additional field country_id and countries table with id, text and capital_name fields. Is it possible to receive capital name in this way $user->country->capital_name ?
Hasin Hayder
December 26th, 2007 at 1:51 pm
6@victor - No, that creates too much auto processing at the backend and this is why we decided not to create an ORM, but a modified Active Record.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Links
Meta
Calendar
Orchid is proudly powered by WordPress - BloggingPro theme by: Design Disease