Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 428

Show
Ignore:
Timestamp:
04/06/07 08:24:59
Author:
fumanchu
Message:

Looks like Geniusql adaptation is solidifying (ADO and Postgres both work at least). Time to upgrade Dejavu trunk to it.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/storage/db.py

    r427 r428  
    5353        self.reserve_lock = threading.Lock() 
    5454         
    55         # Adapter Overrides 
     55        # Config Overrides 
    5656        def get_option(name): 
    5757            item = allOptions.get(name) 
     
    6060            return item 
    6161         
    62         adapter = get_option('Database Class') 
    63         if adapter
    64             self.databaseclass = adapter 
     62        dbclass = get_option('Database Class') 
     63        if dbclass
     64            self.databaseclass = dbclass 
    6565         
    6666        allOptions = dict([(str(k), v) for k, v in allOptions.iteritems()]) 
     
    407407                               % (oldname, t.name)) 
    408408            oldcol = c[0] 
    409             pytype1 = self.db.typeadapter.python_type(oldcol.dbtype) 
    410             # Note we use newname, which assumes that property is in the class. 
    411             pytype2 = getattr(cls, newname).type 
    412             oldcol.imperfect_type = not self.db.typeadapter.related(pytype1, pytype2) 
    413409            # Use the superclass call to avoid DROP COLUMN/ADD COLUMN. 
    414410            dict.__setitem__(t, oldname, oldcol) 
     
    528524            dbcols = dict([(c.name, c) for c in table.itervalues()]) 
    529525            indices = cls.indices() 
    530             related = self.db.typeadapter.related 
    531526            for pkey in cls.properties: 
    532527                colname = self.schema._column_name(table.name, pkey) 
     
    572567                        continue 
    573568                 
    574                 # Set imperfect_type 
    575                 newtype = getattr(cls, pkey).type 
    576                 if newtype != col.pytype: 
    577                     col.imperfect_type = not related(newtype, col.pytype) 
    578                     col.pytype = newtype 
     569                col.pytype = getattr(cls, pkey).type 
    579570                 
    580571                # Try to find matching Index objects. Because index names are 
     
    674665         
    675666        for cname, c in table.iteritems(): 
    676             ptype = self.schema.db.typeadapter.python_type(c.dbtype) 
    677             if ptype == int and c.hints.get('bytes') in (1, '1')
     667            ptype = c.pytype 
     668            if ptype == int and c.dbtype.bytes == 1
    678669                # This is probably a bool 
    679670                ptype = bool 
    680                 del c.hints['bytes'] 
    681671            p = AutoUnitClass.set_property(cname, ptype) 
    682672            if c.autoincrement: 
    683673                AutoUnitClass.sequencer = dejavu.UnitSequencerInteger(int, c.initial) 
    684674            p.default = c.default 
    685             p.hints = c.hints.copy() 
     675            p.hints = dict([(k, getattr(c.dbtype, k)) 
     676                            for k in ("bytes", "precision", "scale") 
     677                            if hasattr(c.dbtype, k)]) 
    686678            p.index = (cname in table.indices) 
    687679         
     
    731723        sequencer = None 
    732724        for cname, c in table.iteritems(): 
    733             ptype = self.schema.db.typeadapter.python_type(c.dbtype) 
    734             if ptype == int and c.hints.get('bytes') in (0, '0', 1, '1')
     725            ptype = c.pytype 
     726            if ptype == int and c.dbtype.bytes == 1
    735727                # This is probably a bool 
    736728                ptype = bool 
    737                 del c.hints['bytes'] 
    738729             
    739730            mod = ptype.__module__ 
     
    757748                index = ", index=True" 
    758749             
    759             hints = "" 
    760             if c.hints: 
    761                 hints = ", hints=%r" % c.hints 
     750            hints = dict([(k, getattr(c.dbtype, k)) 
     751                          for k in ("bytes", "precision", "scale") 
     752                          if hasattr(c.dbtype, k)]) 
     753            if hints: 
     754                hints = ", hints=%r" % hints 
     755            else: 
     756                hints = "" 
    762757             
    763758            prop = ("    %s = UnitProperty(%s%s%s%s)" 
  • trunk/storage/storeado.py

    r427 r428  
    11import warnings 
    22 
    3 from geniusql.providers import ado 
     3from geniusql.providers import ado, sqlserver, msaccess 
    44from dejavu import errors 
    55from dejavu.storage import db 
    66 
    77 
    8 class StorageManagerADO(db.StorageManagerDB): 
     8class StorageManagerADO_SQLServer(db.StorageManagerDB): 
    99    """StoreManager to save and retrieve Units via ADO 2.7. 
    1010     
     
    1212    """ 
    1313     
    14     databaseclass = ado.ADODatabase 
    15  
    16  
    17 class StorageManagerADO_SQLServer(StorageManagerADO): 
    18      
    19     databaseclass = ado.SQLServerDatabase 
     14    databaseclass = sqlserver.SQLServerDatabase 
    2015     
    2116    def __init__(self, arena, allOptions={}): 
     
    2520 
    2621 
    27 class StorageManagerADO_MSAccess(StorageManagerADO): 
     22class StorageManagerADO_MSAccess(db.StorageManagerDB): 
     23    """StoreManager to save and retrieve Units via ADO 2.7. 
     24     
     25    You must run makepy on ADO 2.7 before installing. 
     26    """ 
    2827    # Jet Connections and Recordsets are always free-threaded. 
    2928     
    30     databaseclass = ado.MSAccessDatabase 
     29    databaseclass = msaccess.MSAccessDatabase 
    3130     
    3231    def __init__(self, arena, allOptions={}): 
     
    3837     
    3938    def _make_column(self, cls, key): 
    40         col = StorageManagerADO._make_column(self, cls, key) 
     39        col = db.StorageManagerDB._make_column(self, cls, key) 
    4140        if col.dbtype == "MEMO": 
    4241            for assoc in cls._associations.itervalues(): 
  • trunk/test/zoo_fixture.py

    r427 r428  
    989989            if db: 
    990990                import math 
    991                 maxprec = db.typeadapter.numeric_max_precision 
     991                maxprec = db.adapterset.numeric_max_precision() 
    992992                if maxprec == 0: 
    993993                    # SQLite, for example, must always use TEXT. 
     
    11601160                        v2 = copy.hints.get(k) 
    11611161                        if v2 != 0 and v2 < v: 
    1162                             self.fail("%s.%s hint[%s] %s not >= %s" % 
     1162                            self.fail("%s.%s hints[%s]: %s not >= %s" % 
    11631163                                      (cls.__name__, pname, k, v2, v)) 
    11641164                    else: