Skip to main content

Simple SQLite3 Object Relational Mapper for Python.

Project description

Simple SQLite3 Object Relational Mapper for Python.

Requirements

  • Python 3.3 or later

Features

  • Under construction

Setup

$ pip install SimpleORM

History

0.1.0 (2014-03-13)

  • first release

Example

Define select statement in the source code and get return value as instances of Employee class.

from simpleorm import BaseDao
from classes import Employee
from collections import OrderedDict

class SelectEmployeeAll(BaseDao):
    sql = '''
SELECT A.ID
      ,A.NAME
      ,B.NAME AS BOSS_NAME
  FROM EMPLOYEE A
  LEFT OUTER JOIN EMPLOYEE B
    ON B.ID = A.BOSS
'''

if __name__ == '__main__':
    param = OrderedDict()
    result = SelectEmployeeAll(dbfile = 'test.db', return_type = Employee).execute(param)
    for elem in result:
        print(elem.id, elem.name, elem.boss_name)
class Employee:
    id = None
    name = None
    boss_name = None

Define select statement out of the source code and get return value as tuple.

from simpleorm import BaseDao
from collections import OrderedDict

class SelectEmployee(BaseDao):
    pass

if __name__ == '__main__':
    param = OrderedDict()
    param['name'] = 'Taro%'
    result = SelectEmployee(dbfile = 'test.db').execute(param)
    for elem in result:
        print(elem['ID'], elem['Name'], elem['age'], elem['bOsS'])
-- select_employee.sql
SELECT ID
      ,NAME
      ,AGE
      ,BOSS
  FROM EMPLOYEE
 WHERE NAME LIKE ?
 ORDER BY AGE ASC

Define insert statement.

from simpleorm import BaseDao
from collections import OrderedDict

class InsertEmployee(BaseDao):
    sql = 'INSERT INTO EMPLOYEE (ID, NAME, AGE, BOSS) VALUES (?, ?, ?, ?)'

if __name__ == '__main__':
    param = OrderedDict()
    param['id'] = 4
    param['name'] = 'Jiro Tanaka'
    param['age'] = 24
    param['boss'] = 3
    result = InsertEmployee(dbfile = 'test.db').execute(param)
    print(result)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for SimpleORM, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size SimpleORM-0.1.0.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page