Skip to main content

DB wrapper library

Project description

Overview

Simple library that makes working with databases more convenient in python.

notanorm can return objects instead of rows, protects you from injection, and has a very simply driver interface.

Decidedly not an ORM, since ORM's are typically mega libraries with often confusing semantics.

Example:

from notanorm import SqliteDb 
from notanorm import MysqlDb 

fname = ":memory:"

# default options are 
db = SqliteDb(fname)

# no special create support, just use a string
db.query("create table foo (bar text, iv integer primary key)")

# insert, select, update, and upsert are convenient and do the right thing
# preventing injection, normalizing across db types, etc.

db.insert(bar="hi", iv=1)
db.insert(bar="hi", iv=2)
db.insert(bar="ho", iv=3)

db.upsert(bar="ho", iv=4)                   # primary keys are required for upserts

db.select("foo", bar="hi")[0].bar           # hi
db.select("foo", {"bar": "hi"})[0].iv       # 1

db.count("foo", bar="hi")                   # 2

class Foo:
    def __init__(self, bar=None, iv=None):
        self.bar = bar
        self.iv = iv

# create a class during select
db.register_class("foo", Foo)
obj = db.select_one("foo", bar="hi")
print(obj.bar)                              # hi

Database support

sqlite3 drivers come with python

To use mysql, pip install mysqlclient, or if that is not available, pip install pymysql

Project details


Download files

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

Built Distribution

notanorm-2.1.0-py3-none-any.whl (15.9 kB view hashes)

Uploaded py3

Supported by

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