Skip to main content

MoSQL is a lightweight Python library which assists programmer to use SQL.

Project description

MoSQL is a lightweight Python library which assists programmer to use SQL.

It has two major parts:

The first part is SQL builders which help you to build SQL with common Python data types:

>>> from mosql.common import select
>>> select('person', {'age >': 18})
'SELECT * FROM person WHERE age > 18'

It converts the Python data types to SQL statements. You can find more exmaples in mosql.common.

The second part is a easy-to-use interface of the result set. We assume there is a table like this:

db=> select * from detail where person_id='mosky';
 detail_id | person_id |   key   |   val
-----------+-----------+---------+---------
         4 | mosky     | address | address
         3 | mosky     | address | ...
        10 | mosky     | email   | email
         6 | mosky     | email   | ...
         1 | mosky     | email   | ...
(5 rows)

After setuped the mosql.result.Model, it is more easy to access this table:

>>> from my_models import Detail
>>> for detail in Detail.find(person_id='mosky')):
...     print detail
{'person_id': 'mosky', 'detail_id': [3, 4], 'val': ['address', '...'], 'key': 'address'}
{'person_id': 'mosky', 'detail_id': [1, 6, 10], 'val': ['email', '...', '...'], 'key': 'email'}

For simplicity, the mosql.result.Model is rendered as a dict, and the lists in the :mosql.result.Model are not simple lists, too. They are mosql.result.Column which act as a proxy. It will redirect your operations on it to the mosql.result.Model which it belongs to.

Start with MoSQL’s model describes more details about how to use`mosql.result.Model`.

Installation

It is easy to install MoSQL with pip:

$ sudo pip install mosql

Or clone the source code from Github:

$ git clone git://github.com/moskytw/mosql.git

You can find the full documentation at mosql.mosky.tw.

Project details


Download files

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

Source Distribution

mosql-0.1.0.tar.gz (18.6 kB view details)

Uploaded Source

File details

Details for the file mosql-0.1.0.tar.gz.

File metadata

  • Download URL: mosql-0.1.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mosql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ca31218e39267ceebf1811b47eb6ec01f4b8da5d40a05b3153623b2e9945080e
MD5 cd6cc017b4ecd54ac9c1b66b1537d03a
BLAKE2b-256 516b934e6b5de81f20b8a3df8aba848c3f2f34cddb47da36df9bf7264e95fd77

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page