Skip to main content

Relational Database Management System

Project description

RDBMS

Relational Database Management System

Installing

Install and update using pip3:

$ pip3 install rdbms

Python 3 and newer.

Simple Usage

from rdbms import RDBMS


class User(RDBMS):
    path = './test_sqlite.db' # default in-memory usage

    def setup(self):
        """
        CREATE TABLE IF NOT EXISTS  user
        (
         id INTEGER   PRIMARY KEY   AUTOINCREMENT,
         name         TEXT          NOT NULL UNIQUE,
         password     CHAR(200)
         );
        """

    def create_user(self, name, password):
        """
        INSERT INTO user (name, password)
        VALUES ('{name}', '{password}')
        """

    def get_user(self, name):
        """
        SELECT * FROM user
        WHERE name = '{name}'
        """

    def execute_script_example(script=True):
       """
       Run script
       """


if __name__ == '__main__':
    user = User()
    user.create_user(name='username', password='1234')
    users = user.get_user(name='username')
    assert users[0].name == 'username'
    assert users[0].name == users[0]['name']

Parameters Example

from rdbms import RDBMS


class Test(RDBMS):
    def setup(self): # not required | script parameter defaults to True for setup function
        """
        Some SQL script
        """

    def script_execute(self, script=True): # run script | script default False
        """
        Some SQL script
        """

    def iterable_object(self, iterable=True): # return generator | iterable default False
        """
        Some SQL query
        """

    def fixed_size(self, size=1): # fixed size data return | size default None
        """
        Some SQL query
        """

Function Example

from rdbms import RDBMS


def titlecase(text):
    return text.title()

class Test(RDBMS):
    ...

    def get_test_function_data(self, data):
        """
        SELECT titlecase(name) FROM test WHERE name='{data}'
        """


if __name__ == '__main__':
    test = Test()
    test.add_function(titlecase)
    result = self.test.get_test_function_data(data='test name')
    assert result[0].name == 'Test Name'

Aggregate Example

from rdbms import RDBMS


class mysum:
    def __init__(self):
        self.count = 0

    def step(self, value):
        self.count += value

    def finalize(self):
        return self.count

class Test(RDBMS):
    ...

    def get_test_aggregate_data(self):
        """
        SELECT mysum(age) FROM test
        """


if __name__ == '__main__':
    test = Test()
    test.add_aggregate(mysum)
    result = test.get_test_aggregate_data()
    assert result[0]['mysum(age)'] == 100

Collaction Example

from rdbms import RDBMS


def collate_reverse(string1, string2):
    if string1 == string2:
        return 0
    elif string1 < string2:
        return 1
    else:
        return -1

class Test(RDBMS):
    ...

    def get_test_collation_data(self):
        """
        SELECT name FROM test ORDER BY name COLLATE collate_reverse
        """


if __name__ == '__main__':
    test = Test()
    test.add_collaction(collate_reverse)
    result = test.get_test_collation_data()
    assert result[0]['name'] == 'b'
    assert result[1]['name'] == 'a'

Text Factory Example

from rdbms import RDBMS
from rdbms.text_factories import text_factory_bytes


class Test(RDBMS):
    ...


if __name__ == '__main__':
    test = Test()
    test.set_text_factory(text_factory_bytes)
    data = test.get_data()
    assert result[0].attribute, bytes

Row Factory Example

from rdbms import RDBMS
from rdbms.text_factories import dict_factory


class Test(RDBMS):
    ...


if __name__ == '__main__':
    test = Test()
    test.set_row_factory(dict_factory)
    data = test.get_data()
    assert 'attribute' in result[0]

Support

  • Python 3.x

  • Supports all operating systems

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

rdbms-1.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

rdbms-1.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file rdbms-1.0.2.tar.gz.

File metadata

  • Download URL: rdbms-1.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for rdbms-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a45ebdb4c2696b1763cb3e9726d11bff688c352002036ab2d68ab363b0973edb
MD5 549407f2098b5cb911b9925a16e32b7e
BLAKE2b-256 01e184470fb8aff19765a10da5f19240ab7e8988ac0cbaf183c406bc1b2f0a43

See more details on using hashes here.

File details

Details for the file rdbms-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: rdbms-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for rdbms-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 501b2fb77bef159c776bd82c5c5f1c540c600a31e84ee9b0fee1c405d23692bf
MD5 323fc33bc9ccae79f20815aa5d14fd14
BLAKE2b-256 8519dd4db1c85af96eb49b4b46422e7ecc0ee68a43581a1427b84a0dbd53fd8a

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