Class key
source code
- Known Subclasses:
-
foreign_key,
primary_key
This class manages keys of dbobjects (not dbclasses! The object must
be initialized for this to work). It is instantiated by
dbobject.__init__(), among others, using the __primary_key__ attribute to
set it up.
There are a number of methods in this class which come in pairs: a
singular one and a plural one. attribute() for instance returns returns
the name of the dbobj's key attribute, if, and only if, the key is a
single column key. If the key has multiple column, it will raise an
exception. This is true also for column() and value(). The plural form of
these functions is more generic: it will return a generator(!) yielding
the requested objects, a generator with only one element for single
column keys, a generator with several element for multiple column
keys.
I know the way this is imlemented below duplicates a lot of code and
could be optimized. But since this would make the code much harder to
understand and these functions are not likely to change in principle,
I've decided to write it this way.
__init__(self,
dbobj,
*key_attributes)
(Constructor)
| source code |
-
- Parameters:
dbobj - Dbobj that this key belongs to. (If you pass a dbclass
instead of a dbobj, all functionality will work that doesn't
depend on actual data).
key_attributes - Those attribute(s) the key consists of
|
-
- Returns:
- True, if all attributes that are needed for this key are set
within the dbobj.
|
-
- Returns:
- An string containing the name of the attribute managing the
key column.
- Raises:
|
-
- Returns:
- A tuple of strings naming the db attributes managing the key
columns.
|
-
- Returns:
- An datatype instance managing the key attribute.
- Raises:
|
-
- Returns:
- A generator yielding the datatype instances that comprise the
key
|
-
- Returns:
- An sql.column instance indicating the key's column.
- Raises:
|
-
- Returns:
- A tuple of sql.column instances that comprise the key
|
-
- Returns:
- The value of the key as a Python data object
- Raises:
|
-
- Returns:
- The value of the key as Python tuple
|
-
- Returns:
- The sql_literal of the key as a Python data object
- Raises:
|
-
- Returns:
- A generator yielding the SQL literals of this key as
strings.
|
-
- Returns:
- sql.where() instance representing a where clause that refers
to this key
|
-
- Returns:
- True - if the other refers to the same key (maybe different
tables!) as this key, otherwise, you guessed it, False. Order of
attributes (i.e. columns) does matter, as it does in SQL!
|