Skip to main content

Provides a simple ORM for MySQL, PostgreSQL and SQLite.

Project description

(Version 0.5.1)

Purpose

Provides an ORM for SQLite.

Usage

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

For example:

DbObject = myorm.DbObject DbObject.adaptor = myorm.SQLiteAdaptor(database=’database.db’)

class User(DbObject):

name = myorm.CharField(max_length=25) password = myorm.CharField(max_length=50) describtion = myorm.TextField() registered = myorm.DateField() logins = myorm.IntegerField() active = myorm.BooleanField(default=True)

Users automatically get an additional id which is an instance if myorm.PkField.

Instance methods:

  • .save()
    • Simply saves the object. If it is new, it will be created, if it already exists, it will be updated.

  • .delete()

Class methods

  • .create_table()
    • Function to create tables. The class which calls this function will get a table in the database. It DOES NOT provide migrations (at the moment), it simply creates a table.

The class provides an interface to create objects: The objects manager. It is available as in User.objects.get()

Manager operations:

User.objects

  • .all()
    • Returns all objects, unordered

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

  • .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).

  • .exclude(key=value)

  • .create()
    • Used to create objects of the calling class. Takes fieldnames as kwargs. E.g. User.objects.create(name=’Christian’, ..) It returns the just created object.

  • .oder_by(‘name’)

  • .count()

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. E.g. DbObject.raw(“INSERT INTO user (name, description) VALUES (?, ?)”, ‘Christian’, ‘myorm developer.’)

License

myorm 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

myorm-0.5.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

myorm-0.5.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file myorm-0.5.1.tar.gz.

File metadata

  • Download URL: myorm-0.5.1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for myorm-0.5.1.tar.gz
Algorithm Hash digest
SHA256 8ade28670766198364351870df175c0845d913f289cc4c2aa7ca4af9cc6a827d
MD5 dd8f5de8b63a59331e58486537b0c11b
BLAKE2b-256 6adbf9dac1bcbf8dfe523071ca2e7762e43caa57db144267e02a41b4f05c91e2

See more details on using hashes here.

File details

Details for the file myorm-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: myorm-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for myorm-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9dca76dbc3ad1f07a353a347ad99e75e9dd6bee06bf10a1aff33f922b6cb8ac4
MD5 92a11f737fe01c4d99e4d5ee7d934515
BLAKE2b-256 ecb756d0b394f2659138a1ace7b7c2cd37b5f82e288dc17e139f7c57d45ba6ee

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