newbie question - writing derived view back to db
Marcin Krol <[email protected]>
| Newsgroups | gmane.comp.db.metakit |
|---|---|
| Message-ID | <[email protected]> |
Hello everyone,
I'm new to Metakit and I use it via the Python interface. What I have
trouble figuring out is how to write the derived view back to the db.
I wrote this script that stores the word with its integer index in the
db (code below). Now supposed I get the view with:
import metakit
db=metakit.storage('small.mk',1)
vw=db.view('words')
..then sort it:
vw2=vw.sort('word')
I checked that it gives me derived view sorted as I expected.
However, then I stumbled on seemingly silly problem: how do I write
the damn thing back to the db? db.commit() doesn't seem to write the
changes back to db.
I can always use storage.save(new_fileobj) and then delete the old db.
However, that's a lot of rigmarole just to write the changed view
back.
# begin of code
import metakit
bwl = list(open('smallist.txt').readlines())
db = metakit.storage('small.mk',1)
vw = db.getas('words[word:S,idx:L]')
for word, idx in zip(bwl, range(0,len(bwl))):
vw.append(word=word.strip('\n'),idx=idx)
db.commit()
# end of code
Regards,
Marcin
_____________________________________________
Metakit mailing list - [email protected]
http://www.equi4.com/mailman/listinfo/metakit