A light weight mysql client library.
Project description
Lorm: A light weight mysql client library.
=================================
.. image:: https://img.shields.io/pypi/v/lorm.svg
:target: https://pypi.python.org/pypi/lorm
Lorm is a light weight mysql client library for Python.
Built-in connection pool, Django style lookup expressions.
Installation
------------
The last stable release is available on PyPI and can be installed with ``pip``::
$ pip install lorm
Example
--------
.. code:: sql
CREATE TABLE `pets` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL DEFAULT '',
`add_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
**Connect to Mysql**
.. code:: python
>>> db = lorm.Hub()
>>> db.add_pool('default', host='localhost', port=3306, user='root',
passwd='root', db='test', autocommit=True, pool_size=8, wait_timeout=30)
**Insert**
.. code:: python
>>> db.default.pets.create(name='cat')
1
**Query**
.. code:: python
>>> db.default.pets.get(id=1)
{u'id': 2, u'name': u'cat'}
**Row Style**
.. code:: python
>>> db.default.pets.filter(id__lt=10).select('id')[:]
[{u'id': 1}, {u'id': 2}, {u'id': 4}, {u'id': 5}, {u'id': 6}, {u'id': 7}, {u'id': 8}, {u'id': 9}]
>>> db.default.pets.filter(id__lt=10).values('id')[:]
((1,), (2,), (4,), (5,), (6,), (7,), (8,), (9,))
>>> db.default.pets.filter(id__lt=10).flat('id')[:]
[1, 2, 4, 5, 6, 7, 8, 9]
**Raw SQL**
.. code:: python
>>> db.default.fetchall("select * from pets")
((1, u'cat'), (2, u'dog'), (3, u'bird'))
**Transaction**
.. code:: python
>>> with db.default as c:
>>> print c.pets.create(name='fish')
For more examples, see `example.py <https://github.com/zii/lorm/blob/master/example.py>`_
Features
--------
- Built-in Connection pool
- Django style lookup expressions
- Threading safe
- Gevent friendly
Requirements
------------
- pymysql or MySQL-python
=================================
.. image:: https://img.shields.io/pypi/v/lorm.svg
:target: https://pypi.python.org/pypi/lorm
Lorm is a light weight mysql client library for Python.
Built-in connection pool, Django style lookup expressions.
Installation
------------
The last stable release is available on PyPI and can be installed with ``pip``::
$ pip install lorm
Example
--------
.. code:: sql
CREATE TABLE `pets` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL DEFAULT '',
`add_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
**Connect to Mysql**
.. code:: python
>>> db = lorm.Hub()
>>> db.add_pool('default', host='localhost', port=3306, user='root',
passwd='root', db='test', autocommit=True, pool_size=8, wait_timeout=30)
**Insert**
.. code:: python
>>> db.default.pets.create(name='cat')
1
**Query**
.. code:: python
>>> db.default.pets.get(id=1)
{u'id': 2, u'name': u'cat'}
**Row Style**
.. code:: python
>>> db.default.pets.filter(id__lt=10).select('id')[:]
[{u'id': 1}, {u'id': 2}, {u'id': 4}, {u'id': 5}, {u'id': 6}, {u'id': 7}, {u'id': 8}, {u'id': 9}]
>>> db.default.pets.filter(id__lt=10).values('id')[:]
((1,), (2,), (4,), (5,), (6,), (7,), (8,), (9,))
>>> db.default.pets.filter(id__lt=10).flat('id')[:]
[1, 2, 4, 5, 6, 7, 8, 9]
**Raw SQL**
.. code:: python
>>> db.default.fetchall("select * from pets")
((1, u'cat'), (2, u'dog'), (3, u'bird'))
**Transaction**
.. code:: python
>>> with db.default as c:
>>> print c.pets.create(name='fish')
For more examples, see `example.py <https://github.com/zii/lorm/blob/master/example.py>`_
Features
--------
- Built-in Connection pool
- Django style lookup expressions
- Threading safe
- Gevent friendly
Requirements
------------
- pymysql or MySQL-python
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lorm-0.3.7.zip
(11.8 kB
view details)
File details
Details for the file lorm-0.3.7.zip
.
File metadata
- Download URL: lorm-0.3.7.zip
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 619bc4803cd3e672d5477e7818023c5ea55afba256237a0eb37243db44aeadc2 |
|
MD5 | f4eee3f3b25e7f10f397b12e14bd9905 |
|
BLAKE2b-256 | e47d0dfd63fe30453ee6fcea81a81c904d71891e1853098917f97f4a68002305 |