wzugang / sqlapi

Simple Sql to Db abstraction in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A very simple abstraction layer for doing
SQL atop Python's DbApi.

Nothing much really offered apart from some
simple convenience. It is NOT AN ORM!

E.g.
<code>

import sqlapi
 
 
class News(sqlapi.Table):
    @sqlapi.columns
    def select_all(self):
        '''select * from news'''
 
    @sqlapi.columns
    def select_news_by_id(self,id):
        """select * from news where id = '%s'"""
 
 
class Comment(sqlapi.Table):
 
    @sqlapi.columns
    def select_all(self):
        '''select * from comment'''
 
 
def test_fetch():
    conn = sqlapi.connect("sqlite://foo:bar@localhost/sqlapi")
 
    news = News(conn)
    comment = Comment(conn)
 
    for n in news.select_news_by_id(1):
        print n.id, n.head, n.date_created, n.author
 

</code>

About

Simple Sql to Db abstraction in Python


Languages

Language:Python 100.0%