#!/usr/bin/env python
# -*- coding: utf-8 -*-

from base import PostgreSQL

class Person(PostgreSQL):
    clauses = dict(table='person')
    arrange_by = ('person_id', )
    squashed = ('person_id', 'name')
    ident_by = arrange_by

if __name__ == '__main__':

    print '# select all'
    person = Person.select()
    print person
    print person.cols
    print

    print '# select with a condition'
    person = Person.select(where={'person_id': 'mosky'})
    print person
    print person.cols
    print

    print '# arrange entire table'
    for person in Person.arrange():
        print person
    print

    print '# arrange with a condition'
    for person in Person.arrange(where={'person_id': ('mosky', 'andy')}):
        print person
    print

    print '# rename mosky'

    mosky = Person.select(where={'person_id': 'mosky'})
    mosky['name'] = 'Mosky Liu (renamed 1)'
    mosky.name = 'Mosky Liu (renamed 2)'
    mosky.name = 'Mosky Liu (renamed)'
    mosky.save()

    mosky = Person.select(where={'person_id': 'mosky'})
    print mosky.name
    print

    from mosql.util import all

    print '# rename mosky back'
    mosky = Person.update(where={'person_id': 'mosky'}, set={'name': 'Mosky Liu'}, returning=all)
    print mosky
    print

    import mosql.json as json

    print '# json'
    print json.dumps(mosky)
    print

@@ -310,32 +310,45 @@
 lect()%0A    print
+ 'squashed:',
  person%0A    prin
@@ -340,32 +340,45 @@
 person%0A    print
+ 'actually:',
  person.cols%0A   
@@ -377,32 +377,33 @@
 cols%0A    print%0A%0A
+%0A
     print '# sel
@@ -482,32 +482,45 @@
 sky'%7D)%0A    print
+ 'squashed:',
  person%0A    prin
@@ -516,24 +516,37 @@
 on%0A    print
+ 'actually:',
  person.cols
@@ -549,32 +549,33 @@
 cols%0A    print%0A%0A
+%0A
     print '# arr
@@ -653,32 +653,33 @@
 rson%0A    print%0A%0A
+%0A
     print '# arr
@@ -803,24 +803,25 @@
 %0A    print%0A%0A
+%0A
     print '#
@@ -888,24 +888,76 @@
 : 'mosky'%7D)%0A
+    # model expands the change for columns squashed%0A
     mosky%5B'n
@@ -957,16 +957,13 @@
 osky
-%5B'
+.
 name
-'%5D
  = '
@@ -985,16 +985,59 @@
 med 1)'%0A
+    # setitem or setattr are also accepted%0A
     mosk
@@ -1029,37 +1029,40 @@
 cepted%0A    mosky
-.
+%5B'
 name
+'%5D
  = 'Mosky Liu (r
@@ -1119,20 +1119,121 @@
     
-mosky.save()
+# model will merged the updates when save%0A    Person.dump_sql = True%0A    mosky.save()%0A    Person.dump_sql = False
 %0A%0A  
@@ -1314,24 +1314,25 @@
 %0A    print%0A%0A
+%0A
     from mos
@@ -1508,16 +1508,17 @@
  print%0A%0A
+%0A
     impo

refined the person.py