help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Magic files for reading/writing to a database


From: Greg Detre
Subject: Magic files for reading/writing to a database
Date: 28 Jan 2007 17:45:38 -0800
User-agent: G2/1.0

Dear all,

I'm trying to build a magic files interface that will allow
me to read/write records from a sql database as if they're
files. I can see many applications of this - for instance,
one could edit blog or wiki entries in a database directly,
as though they were flat files.

I've been able to read the information from the database
using a combination of Pymacs (to interface my elisp code
with python code) and Sqlalchemy, an awesome high-level
python library that interfaces with sqlite, mysql, postgres
and other database engines in a nice object-oriented way. So
I can call some function like (magiql-get-contents pkey) and
have it return the text I want, and then save any
modifications back to the database in a very natural way. So
far so good.

The next magic files step is to handle the (magiql-get-contents)
and (magiql-write-contents) functions with a
file-name-handler function, along with any other auxiliary
functions I might need. I want to be able to deal with a
sqlite file like this:

  magiql:~/mydatabase.db:1

where 'magiql' is the name of the package i'm writing,
~/mydatabase.db is a sqlite file, and 1 is the primary key
of the record I'm after. In the future, I hope to generalize
this so that one could use other database engines, or
incorporate SQL code in the filename, but let's keep things
simple.

I've spent a fair while reading and re-reading the brief
section on magic files in the GNU Emacs manual:

http://www.gnu.org/software/emacs/elisp/html_node/Magic-File-
Names.html

and the TRAMP source code, as well as a few of the comments
on gnu.emacs.help, but I haven't been able to find a simple,
documented example that uses magic files. The TRAMP code is
beautifully commented and laid out, but I don't think anyone
would deny that it's complex. Can anyone recommend some
documentation or example code to help me figure out where my
current code is going wrong?

Many thanks in advance,

Yours,

  Greg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]