Skip to main content

A light weight python ORM without models.

Project description

https://img.shields.io/pypi/v/lorm.svg

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

>>> 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

>>> db.default.pets.create(name='cat')
1

Query

>>> db.default.pets.get(id=1)
{u'id': 2, u'name': u'cat'}

Row Style

>>> 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

>>> db.default.fetchall("select * from pets")
((1, u'cat'), (2, u'dog'), (3, u'bird'))

Transaction

>>> with db.default as c:
>>>     print c.pets.create(name='fish')

For more examples, see test.py

Features

  • No model

  • 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.3.zip (11.8 kB view details)

Uploaded Source

File details

Details for the file lorm-0.3.3.zip.

File metadata

  • Download URL: lorm-0.3.3.zip
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lorm-0.3.3.zip
Algorithm Hash digest
SHA256 504463c0c8b62274507a9ec7b0afbd1680689bedea477359c64d0520d58022f8
MD5 3873fe595e5837fcf559c79231c95a5b
BLAKE2b-256 93328a333dcf5deba02fa996092594e524702e50a090ed2d565cffaac426cbb8

See more details on using hashes here.

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