[grassyknoll commit] r981 - in branches/unhork/grassyknoll: collection/backends/sql lib tests

0 views
Skip to first unread message

codesite...@google.com

unread,
Jan 5, 2009, 11:10:53 PM1/5/09
to grassykno...@googlegroups.com
Author: jemfinch
Date: Mon Jan 5 20:08:29 2009
New Revision: 981

Modified:
branches/unhork/grassyknoll/collection/backends/sql/TableMaker.py
branches/unhork/grassyknoll/lib/Model.py
branches/unhork/grassyknoll/tests/test_Model.py

Log:
Issue #159: Added Model code to set __id__ field on schemas; still need to
remove schema-specific code, but all tests pass, so it's a good place to
checkpoint.


Modified: branches/unhork/grassyknoll/collection/backends/sql/TableMaker.py
==============================================================================
--- branches/unhork/grassyknoll/collection/backends/sql/TableMaker.py
(original)
+++ branches/unhork/grassyknoll/collection/backends/sql/TableMaker.py Mon
Jan 5 20:08:29 2009
@@ -50,8 +50,11 @@
self.indexed = indexed
self.optional = optional
self.primary_key = primary_key
-
- # TODO: write idField
+
+ @classmethod
+ def idField(cls):
+ return cls('VARCHAR(255)', optional=False, primary_key=True)
+

sqlId = re.compile(r'^[a-zA-Z_]\w*$')
reservedWords = set("""ALL ALTER AND AS AUTOINCREMENT BETWEEN BY CASE
CHECK COLLATE

Modified: branches/unhork/grassyknoll/lib/Model.py
==============================================================================
--- branches/unhork/grassyknoll/lib/Model.py (original)
+++ branches/unhork/grassyknoll/lib/Model.py Mon Jan 5 20:08:29 2009
@@ -123,6 +123,9 @@
"""
self.__fields__[name] = field

+ def setIdField(self):
+ self.setField('__id__', self.FieldType.idField())
+
def unsetField(self, name):
"""Unsets the field with the given name from __fields__.

@@ -141,10 +144,12 @@
Creates multiple schemas from a single definiton, using with-statement
magic
"""
- def __init__(self, **kwargs):
+ def __init__(self, __id__=True, **kwargs):
super(Model, self).__setattr__('__fields__', {})
super(Model, self).__setattr__('_in_with', False)
super(Model, self).__setattr__('__schemas__', kwargs)
+ for schema in self.__schemas__.values():
+ schema.setIdField()

def __enter__(self):
super(Model, self).__setattr__('_in_with', True)

Modified: branches/unhork/grassyknoll/tests/test_Model.py
==============================================================================
--- branches/unhork/grassyknoll/tests/test_Model.py (original)
+++ branches/unhork/grassyknoll/tests/test_Model.py Mon Jan 5 20:08:29 2009
@@ -19,12 +19,15 @@


class Wrapper(Field):
- def __init__(self, wrapped, pants=None, shirt=None):
+ def __init__(self, wrapped, pants=None, shirt=None, is_id=False):
self.wrapped = wrapped
self.pants = pants
self.shirt = shirt
+ self.is_id = is_id

- # XXX idField?
+ @classmethod
+ def idField(cls):
+ return cls('__id__', is_id=True)


class MySchema(Schema):
@@ -232,7 +235,7 @@

print norm.__fields__.keys()
assert_sorted_equals(norm.__fields__,
- ('size', 'color', 'price', 'description'))
+
['__id__', 'size', 'color', 'price', 'description'])

def test_Model_with_TableMaker():
table = TableMaker.Table("the_table").default(indexed=True)

Reply all
Reply to author
Forward
0 new messages