开发者

Create sqlite virtual table in Python

I want to create a SQL-like interface for a special data source which I can query using Python. That is, I have a data source with a number of named iterable containers of entities, and I would like to be able to use SQL to filter, join, sort and preferably update/insert/delete as well.

To my understanding, sqlite3's virtual table functionality is quite suitabl开发者_Go百科e for this task. Is it possible to create the necessary bindings in Python? I understand that the glue has to be c-like, but my hope is someone already wrote a Python wrapper in C or using ctypes.

I will also accept an answer for a better/easier way of doing this.


You can do this by registering a virtual table in SQLite with the APSW Python bindings.

An example for talking to CouchDB using APSW.

There's a similar capability for Perl, namely: Create SQLite Virtual Table extensions in Perl

Finally, if you want to make a Python-based virtual table in PostgreSQL 9.1, check out http://multicorn.org/.


Sounds like you can use SQLAlchemy to persist these objects to sqlite3, possibly to an in :memory: db, and issue both object and table level (raw sql) queries. You can also update/insert/delete them easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜