Skip to main content

Provides an ORM for MySQL, PostgreSQL and SQLite.

Project description

Tests

Nopea

(Version 0.0.16)


Purpose

Provides an ORM for MySQL, PostgreSQL and SQLite.

Usage

To use the power of Nopea you need to set up an adaptor and let your classed inherit from nopea.DbObject.

Setting up Adaptor and Connection

from nopea.dbobject import DbObject
from nopea.adaptors.sqlite import SQLiteAdaptor

DbObject = DbObject
DbObject.adaptor = SQLiteAdaptor('nopea.db')

Creating a subclass

class User(DbObject):
    name = nopea.CharField(max_length=25)
    password = nopea.CharField(max_length=50)
    describtion = nopea.TextField()
    registered = nopea.DateField()
    logins = nopea.IntegerField()
    active = nopea.BooleanField(default=True)

Users automatically get an additional id field which is an instance of nopea.fields.PkField.

Instance methods:

instance.save()
# Simply saves the object. If it is new, it will be created, if it already exists, it will be updated. Depending on whether the instance has an id != None or not.

instance.delete()
# The instance will be delete from the removed from the database. The instance will not be deleted and keep it's original id.

Class methods

User.create_table()
# Function to create tables.
# The class which calls this function will get a table in the database.

Manager operations:

The class provides an interface to create objects: The objects manager.

User.objects.all()
# Returns all objects, unordered

User.objects.get(key=value)
# E.g.: User.objects.get(id=2) Returns one object

User.objects.filter(key=value)
# E.g.: User.objects.filter(active=True) Returns a list of
# objects (like `get` but returns more than one).

# key__lt, key__lte, key__gte and key__gt can be used to limit
# the results. lte means 'lower than equal',
# lt means 'lower than', gte means 'greater than equal' and
# gt means 'greater than'

# E.g. "logins__lt=10". This will return all users with less
# than 10 logins.

# The filters can be combined:

User.objects.filter(logins__gte=10, logins__lte=50)

User.objects.exclude(key=value)
# Returns all results where the the value of the row does not match.

User.objects.create()
# Used to create objects of the calling class.
# Takes fieldnames as kwargs. E.g.

User.objects.create(name='Christian')
# returns the just created object.

User.objects.order_by('name')
# Returns a list of matching object. Can be used with a leading - to
# reverse the order.

User.objects.count()
# Returns the number of mathing rows.

DbObject class methods

DbObject.raw(query, args)
# The builtin SQL injection function.
# It simply executes queries and can be used with arguments.
# It always returns what it fetches. Use it wisely.

DbObject.raw(
    "INSERT INTO user (name, description)
     VALUES (?, ?)", 'Christian', 'Nopea developer.'
    )

License

Nopea is available under the terms of the GPLv3.

Disclaimer

This software comes without any warranty. You use it on your own risk. It may contain bugs, viruses or harm your software and hardware in another way. The developer is not responsible for any consequences which may occur caused by using the software.

Project details


Download files

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

Source Distribution

nopea-0.0.25.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

nopea-0.0.25-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file nopea-0.0.25.tar.gz.

File metadata

  • Download URL: nopea-0.0.25.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.20

File hashes

Hashes for nopea-0.0.25.tar.gz
Algorithm Hash digest
SHA256 967a52d388562ad3e8b005162d7207c95e8fda8c59ee9fee7ed4530e3cd64b45
MD5 13af08042296d7810a2cb6395bb709fa
BLAKE2b-256 c08ca6eb739bc04f7a9a5914727ea7643d3bd2901e545084f5b4f8af2cb3b989

See more details on using hashes here.

File details

Details for the file nopea-0.0.25-py3-none-any.whl.

File metadata

  • Download URL: nopea-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.20

File hashes

Hashes for nopea-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 2b441a87997ecd99f9df929d44b387fafdf6f0a6cf72f739a0d019067d2b8abd
MD5 2e7f776cdfd9b610a03f80808b2a7d3f
BLAKE2b-256 062696d5710c74012d1db0ea72f14d5b9e82720f4e0b71b5d5f959847b1af589

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