[storm] How to retrieve data by store.find for dynamic class-object design of database schema?
Drake Guan
drake at ms.digimax.com.tw
Tue Jan 5 06:43:27 GMT 2010
Hi,
I just started to use ORM and Storm is my first trial. This is a long
question and I will try to make it short and clear.
============ database schema ===========
CREATE TABLE IF NOT EXISTS `MetaEntity` (
`id` int(11) unsigned NOT NULL auto_increment,
`type` varchar(255) NOT NULL,
`supertype` int(11) unsigned default NULL,
`title` varchar(255) default '',
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
`modifiedBy` varchar(255) default '',
PRIMARY KEY (`id`),
UNIQUE KEY `type` (`type`),
KEY `supertype` (`supertype`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
CREATE TABLE IF NOT EXISTS `MetaField` (
`id` int(11) unsigned NOT NULL auto_increment,
`parent` int(11) unsigned NOT NULL,
`name` varchar(255) default '',
`dataType` varchar(255) default '',
`title` varchar(255) default '',
`description` varchar(511) default '',
`defaultValue` varchar(255) default '',
`permission` varchar(255) default '',
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `parent` (`parent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=96 ;
CREATE TABLE IF NOT EXISTS `Entity` (
`id` int(11) unsigned NOT NULL auto_increment,
`metaId` int(11) unsigned NOT NULL,
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `metaId` (`metaId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10593 ;
CREATE TABLE IF NOT EXISTS `Field` (
`id` int(11) unsigned NOT NULL auto_increment,
`parentEntity` int(11) unsigned NOT NULL,
`metaId` int(11) unsigned NOT NULL,
`value` varchar(255) default '',
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
`modifiedBy` varchar(255) default '',
PRIMARY KEY (`id`),
KEY `type` (`metaId`),
KEY `parent` (`parentEntity`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=86780 ;
CREATE TABLE IF NOT EXISTS `Link` (
`id` int(11) unsigned NOT NULL auto_increment,
`anchor1` int(11) unsigned NOT NULL,
`anchor2` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `anchor1` (`anchor1`),
KEY `anchor2` (`anchor2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10592 ;
===================================================
I am trying to make a database schema supporting dynamic class
definitions, objects,
and dynamic relations between objects.
MetaEntity and MetaField are used to provide class definitions.
MetaEntity is for class
definition with id and type(class name) while MetaField is provided for
definitions of member data.
Ex,
If I would like to have a class as following:
def People():
name (str)
age (int)
gender (str)
there would be one row in MetaEntity and three rows in MetaField as
following:
MetaEntity.id, MetaEntity.type, ...
1, "People", ...
MetaField.id, MetaField.parent, MetaField.name, MetaField.dataType, ...
11, 1, "name", "string", ...
12, 1, "age", "int", ...
13, 1, "gender", "string", ...
then, if there are 2 objects(instances) of this class (People), there
would be totally 6 rows as following:
Entity.id, Entity.metaId, ...
21, 1, ...
22, 1, ...
Field.id, Field.parentEntity, Field.metaId, Field.value, ...
31, 21, 11, "George Lucas", ...
32, 21, 12, "60", ...
33, 21, 13, "male", ...
34, 22, 11, "Mary Wonder", ...
35, 22, 12, "55", ...
36, 22, 13, "female", ...
===================================
My first question is:
How can I make use of store to retrieve entities which are "male", or
"older than 50", or "name starts with G", ...?
Yours,
Drake
--
Shuen-Huei (Drake) Guan
R&D Manager, Digimax Inc., Taipei/Taiwan
http://www.digimax.com.tw/
More information about the storm
mailing list