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.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

notanorm-1.2.1-py3-none-any.whl (15.4 kB view hashes)

Uploaded Python 3

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