gnumed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnumed-devel] proposal for dbapi base class


From: Horst Herb
Subject: [Gnumed-devel] proposal for dbapi base class
Date: Mon, 20 Jan 2003 23:18:45 +1100
User-agent: KMail/1.4.3

class PureVirtualFunction:
        pass

class dbapi:
        """Base class for Gnumed database client API objects.
        No functionality in itself, just the root of an object hierarchy
        in order to encourage API consistency"""

        def __init__(self):
                self._dict = {}
                self._created = 0
                self._fetched = 0

        def new(self, **kwargs):
                """create a new record using the fields from the argument 
dictionary
                (which may be empty). Returns the primary key if applicable"""
                raise PureVirtualFunction

        def fetch(self, pkey):
                """fetch the record as identified by the primary key pkey.
                The record can then be accessed via class attributes"""
                raise PureVirtualFunction

        def find(self, **kwargs):
                """find a record as indentified by all dictionary values passed 
as
                argument. Case insensitive arguments are preceded by a '~', 
partial matches
                have a '*' as last character.
                Example: {'firstname':'~Jo*', 'surname':'~miller'} as argument 
finds
                John Miller, Joe miller, JONATHAN MILLER etc.
                Returns a list of dictionaries containing the matching 
records"""
                raise PureVirtualFunction

        def save(self):
                """saves the current record
                Returns 0 if failure, primary key if success"""
                raise PureVirtualFunction

        def undo(self):
                """restores the record as it was read from the backend or 
created anew
                Returns 0 if failure, primary key if success"""
                raise PureVirtualFunction

        def delete(self):
                """deletes the current record from the backend if this is 
permitted
                Returns 0 if failure, 1 if success"""
                raise PureVirtualFunction

        def __setattr__(self, key, item):
                self.__setitem__(key, item)

        def __getattr__(self, key):
                return self.__getitem__(key)
                
        def __setitem__(self, key, item):
                self.__dict__[key] = item

        def __getitem__(self, key):
                return self.__dict__[key]





reply via email to

[Prev in Thread] Current Thread [Next in Thread]