From 3b68c258fd527c15633162ef7312e52fbc71db47 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 16 Jul 2005 01:44:52 +0000 Subject: [PATCH] --- lib/sqlalchemy/mapper.py | 58 ++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/sqlalchemy/mapper.py b/lib/sqlalchemy/mapper.py index 252bac984d..dfd8bafa3e 100644 --- a/lib/sqlalchemy/mapper.py +++ b/lib/sqlalchemy/mapper.py @@ -31,7 +31,6 @@ usermapper = Mapper( addressmapper = Mapper(Address, addresses, properties = { 'street': addresses.address_1, - '*' : addresses }) """ @@ -39,28 +38,71 @@ import sqlalchemy.sql as sql import sqlalchemy.schema as schema class Mapper: - def __init__(self, class_, table, properties): + def __init__(self, class_, table, properties, identitymap = None): self.class_ = class_ self.table = table self.properties = properties + if identitymap is not None: + self.identitymap = identitymap + else: + self.identitymap = _global_identitymap def instance(self, row): pass - - def select_whereclause(self, whereclause, **params): + + def get(self, id): + """returns an instance of the object based on the given ID.""" pass + + def _select_whereclause(self, whereclause, **params): + # make select statement + + + return self._select_statement(statement, **params) + - def select_statement(self, statement, **params): + def _select_statement(self, statement, **params): pass def select(self, arg, **params): + """selects instances of the object from the database. + + arg can be any ClauseElement, which will form the criterion with which to + load the objects. + + For more advanced usage, arg can also be a Select statement object, which + will be executed and its resulting rowset used to build new object instances. + in this case, the developer must insure that an adequate set of columns exists in the + rowset with which to build new object instances.""" if isinstance(arg, sql.Select): - return self.select_statement(arg, **params) + return self._select_statement(arg, **params) else: - return self.select_whereclause(arg, **params) + return self._select_whereclause(arg, **params) def save(self, object): pass def delete(self, whereclause = None, **params): - pass \ No newline at end of file + pass + + +class IdentityMap: + def __init__(self): + self.map = {} + + def get(self, row, class_, table): + """given a database row, a class to be instantiated, and a table corresponding + to the row, returns a corrseponding object instance, if any, from the identity + map. the primary keys specified in the table will be used to indicate which + columns from the row form the effective key of the instance.""" + pass + + def put(self, instance, table): + """puts this object instance, corresponding to a row from the given table, into + the identity map. the primary keys specified in the table will be used to + indicate which properties of the instance form the effective key of the instance.""" + + pass + + +_global_identitymap = IdentityMap() -- 2.47.2