Metakit help
Gordon McMillan
gmcm at hypernet.com
Fri Jul 5 10:10:34 EDT 2002
David LeBlanc wrote:
> Working more with Metakit, i'm finding that there is some information
> not in the documentation, so I have a few questions:
>
> I think I figured out how to create a nested schema, but not how to
> insert or append a row with nested data - how is that done?
Insert / append the containing row. It will have an
empty subview, and row.subview is a view. Insert / append
as needed.
> How do you get a view from a pre-existing database?
storage.view('viewname')
> Can you modify the schema of an existing database? How?
Do another storage.getas(...). Adjusting the type
of a column is (almost) like dropping and adding
the column.
> How do you put a pickle in a database?
Put it in as a B (binary string).
> Are the various attributes of
> that pickle accessable while it's in metakit storage? How about the
> pickled object's attributes?
To Metakit, it's just a binary string.
> How would you enforce a uniqueness constraint on a key field?
Depends. If it's a what in RDBMS-land you'd call a
primary key, I'd make it the first column and
make sure it's sorted (easy when the view's empty :-)).
if isnew:
v = db.getas('myview[key:S,...]')
else:
v = db.view('myview')
v = v.ordered(1)
Now v.find(...) will use a binary search.
If your key is just a unique key, I'd build an
index view '_myview[key:S,ndx:I]'.
Either way, it's pretty easy to wrap the
view so the constraint is enforced. (These
aren't new-style types yet, so you can't
subclass.)
If your view exists:
v = storage.view('myview')
v[:] = v.sort()
storage.commit()
And join the metakit list:
http://www.equi4.com/mailman/listinfo/metakit
-- Gordon
http://www.mcmillan-inc.com/
More information about the Python-list
mailing list