A light weight python ORM without models.
Project description
Lorm is a light weight ORM library for Python, model-less, Django style lookup expressions. It’s suitable for small standalone database script.
Installation
The last stable release is available on PyPI and can be installed with pip:
$ pip install lorm
Example
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
>>> c = lorm.mysql_connect('localhost', 3306, 'root', 'root', 'test')
Insert
>>> c.pets.create(name='cat')
1
Query
>>> c.pets.get(id=1)
{u'id': 2, u'name': u'cat'}
>>> c.last_query
select * from pets where id=1 limit 1
Row Style
>>> c.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}]
>>> c.pets.filter(id__lt=10).values('id')[:]
((1,), (2,), (4,), (5,), (6,), (7,), (8,), (9,))
>>> c.pets.filter(id__lt=10).flat('id')[:]
[1, 2, 4, 5, 6, 7, 8, 9]
Raw SQL
>>> c.fetchall("select * from pets")
((1, u'cat'), (2, u'dog'), (3, u'bird'))
For more examples, see test.py
Features
No Model, use table name directly.
Auto reconnect
Connection pool
Django style lookup expressions
Threading safe
Requirements
pymysql
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.2.20.zip
(9.6 kB
view details)
File details
Details for the file lorm-0.2.20.zip
.
File metadata
- Download URL: lorm-0.2.20.zip
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea9aa9fb824fda64abdfd11e891ccf0680d9e21e4b4dbb53e4a15ec1ac46329d |
|
MD5 | ce02525bd6e744b872dee82700fe3f23 |
|
BLAKE2b-256 | 656964a8dd5796a32b1eafab1b2f64e6fa20c6a945801aff806e7d7a3ce78070 |