[Tutor] mysql store directory information

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Apr 6 20:41:39 CEST 2006



On Thu, 6 Apr 2006, Tiago Saboga wrote:

> As a first part of a project, I need to store a directory tree in a
> mysql db.  I'm wondering if there is a canonical way of doing that. I
> don't know if it's an appropriate question for this list, but I think
> it's not only a choice of db design, but also a choice of appropriate
> python tools.


Hi Tiago,

What are the interesting features of a directory?  You might want to first
model what you want, and then figure out an appropriate database table
structure to represent that model.


> My first approach is a table with the following columns:
> id - path - file name - size

So maybe we can say that a Directory can be modeled as:

######
class Directory:
    def __init__(self, id, path, file_name, size):
        self.id = id
        self.path = path
        self.file_name = file_name
        self.size = size
######

But why will you want to store this structure in the database, if it's
already available on disk?  Why not query the directory directly?


> I'm starting to code it, and I'd like to know if you have a better
> suggestion...

I'd flesh out a few more of the requirements first; the requirement to
store the directory in the database is slightly vague, so you probably
will want to ask more questions about what the problem's really about.



You might find something like SQLObject useful:

    http://www.sqlobject.org/
    http://www.turbogears.org/about/sqlobject.html

where you go fairly directly from data model to SQL table structure with
SQLObject providing the default mapping strategy.



More information about the Tutor mailing list