[ZODB-Dev] AdaptableStorage and OR mapping strategy (was: AdaptableStorage and ZClass instances)
Roché Compaan
roche@upfrontsystems.co.za
Mon, 24 Feb 2003 10:32:13 +0200
> So one still needs to create a gateway per domain class manually (which
> I don't mind as long as it requires less work than it currently does). I
> think a very simple solution would be to have a SQLGatewayBase that have
> methods that generate SQL based on a very simple schema definition in
> subclasses. To take the current SQLProperties class as an example, it
> should only need to have to look like this:
>
> class SQLProperties:
>
> __implements__ = IGateway
>
> schema = RowSequenceSchema()
> schema.addField('id', 'string', 1)
> schema.addField('type', 'string')
> schema.addField('data', 'string')
>
> table_base_name = 'properties'
>
> This will give SQLGatewayBase more than enough to generate all the
> necessary SQL and handle load and store automatically for simple
> mappings. I'll give this a bash with my next try.
I have started rewriting SQLGatewayBase to do more work. So far it's
going well but I wanted to bounce some ideas off you wrt the state that
the load method should return.
Here's my thinking at the moment:
If the schema is of type FieldSchema then the state returned should
be a single value eg.:
items = self.execute(self.readsql(key))
if items:
state = items[0][0]
else:
state = ''
return state, state
If the schema is of type RowSchema then the state returned should be
a sequence and we assert that a single row is returned:
items = self.execute(self.readsql(key))
if items:
assert len(items) = 1
state = items[0]
else:
state = ''
return state, state
If the schema is of type RowSequenceSchema then the state returned
should be a sequence:
items = self.execute(self.readsql(key))
if items:
state = items
# to ensure a hash of the state stays the same
state.sort()
else:
state = []
return state, tuple(state)
If a subclass needs to do something special when computing state it can
simply override the load method.
--
Roché Compaan
Upfront Systems http://www.upfrontsystems.co.za