expanding persistant objects

Jean-Claude Wippler jcw at equi4.com
Mon Mar 27 17:22:28 EST 2000


Pete Shinners wrote:
> 
> i'm learning python here and have a question about storing
> persistant objects. i plan to keep a real simple list of
> users and i want to know the best way to simple store it
> and reload it.
> my only concern is that later i'll probably want to add
> more fields to each users record. can simple pickling
> handle this? do i need to use one of the DB storage
> libraries?
> 
> i'm worried if i start saving the data one way, when i go
> to add extra fields i wont be able to load the files anymore.

That's why the MetaKit database engine does on-the-fly restructuring:
	http://www.equi4.com/metakit/python.html

Example one:
  import Mk4py
  db = Mk4py.Storage('data.mk',1)
  vw = db.getas('people[name:S,age:I]')
  vw.append(name='Tarzan',age=34)
  vw.append(name='Jane',age=23)
  db.commit()

Example two:
  import Mk4py
  db = Mk4py.Storage('data.mk',1)
  vw = db.getas('people[name:S,age:I,city:S]')
  for r in vw:
    r.city = 'Hollywood'
  db.commit()
  for r in vw.sort():
    print r.name, r.age, r.city

If you run one first, and then two, you'll have restructured on the fly.
It'll be instant, regardless of the number of rows.  If for any reason
the transaction is not completed, then neither will the restructure.

-- Jean-Claude



More information about the Python-list mailing list