Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEP for ORM implementation of Python driver (BEP-11) #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions 11/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
```
shortname: 11/PYTHON-ORM-DRIVER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the shortname of this BEP to BEP-11 then we can close issue #32 because all other shortnames have been updated to the BEP-N format.

name: ORM Implementation For Official BigchainDB Python Driver
type: Standard
status: raw
editor: Manan Patel <manan@bigchaindb.com>
```

# Abstract

This is a proposal to implement ORM based wrapper for official bigchaindb [python driver](https://github.com/bigchaindb/bigchaindb-driver). Official driver provides bare bones pyhton API on top of HTTP API to connect to BigchainDB network, but ORM implementation's aim is to provide a CRAB based operational model on top of official python API in order to simplify operations on bigchainDB network - thereby improving community adoption and engagement.

## Language

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [BCP 14](https://tools.ietf.org/html/bcp14) \[[RFC2119](https://tools.ietf.org/html/rfc2119)\] \[[RFC8174](https://tools.ietf.org/html/rfc8174)\] when, and only when, they appear in all capitals, as shown here.

# Motivation

The need for this implementation is driven by following rationale -

* To provide simpler API to interact and perform operations on bigchainDB. Since, traditionally ORM based CRUD (Create, Read, Update, Delete) are the most used basic operations for the database (SQL and NoSQL), CRAB model for blockchains (bigchainDB in this case) reduces the learning curve for non-blockchain developers and improves community engagement. This is specifically true for python developers as Django (one of the most popular python framework) incorporates ORM model to perform CRUD operations.
* Our [ORM implementation](https://github.com/bigchaindb/js-driver-orm) of [javascript driver](https://github.com/bigchaindb/js-bigchaindb-driver) has recently shown good traction and usage within community.
* We would like to keep consistency with implementations related to both - javascript and python, offical drivers.

# Specification

This ORM implmentation is inspired from the ORM implementation of [bigchaindb javascript driver](https://github.com/bigchaindb/js-driver-orm).This ORM SHOULD be implemented on top of python driver - [https://github.com/bigchaindb/bigchaindb-driver](https://github.com/bigchaindb/bigchaindb-driver).
This implementation SHOULD include following **CRAB** operations -

1. **C**reate - performs CREATE transaction with asset payload into bigchainDB.

```python
def create(inputs):
"""
creates the asset in bigchaindb
@param {dict} inputs - dictionary containing keypairs and data for the asset
"""
```
2. **R**etrieve - queries or fetches asset from bigchainDB.

```python
def retrieve(input):
"""
retrieves the asset for a given input query
@param {dict} input - query to retrieve asset
"""
```

3. **A**ppend - performs TRANSFER transaction with asset payload to a given public address in bigchainDB.

```python
def append(inputs):
"""
appends (i.e. transfer transaction) the asset in bigchaindb
@param {dict} inputs - dictionary incl. public key of new owner and private key for current owner
"""
```
4. **B**urn - performs TRANSFER transaction with asset payload to a vanity address (in our case *BurnBurnBurnBurnBurnBurnBurnBurnBurnBurnBurn* - 11 times Burn)

```python
def burn(inputs):
"""
burns the asset to unretrievable address
@param {dict} inputs - dictionary containing details of burn address (i.e. public key)
"""
```

This implementation SHOULD also include tests and code coverage of atleast 95%.


# Architecture


## Current Architecture

![Image of Current Python driver implementation](./images/before-orm-implementation.png)

## Architecture After ORM Implementation

![Image of ORM Python driver implementation](./images/after-orm-implementation.png)

# References

* [CRUD vs CRAB](https://blog.bigchaindb.com/crab-create-retrieve-append-burn-b9f6d111f460)
* [BigchainDB's official python driver](https://github.com/bigchaindb/bigchaindb-driver)
* [BigchainDB's official python driver documentation](https://docs.bigchaindb.com/projects/py-driver/en/latest/index.html)
* [BigchainDB's official javascript driver](https://github.com/bigchaindb/js-bigchaindb-driver)
* [ORM implementation of javascript driver](https://github.com/bigchaindb/js-driver-orm)
* [CRAB tutorial showing javascript ORM driver usage](https://github.com/bigchaindb/tutorial-crab)

# Copyright Waiver

_To the extent possible under law, the person who associated CC0 with this work has waived all copyright and related or neighboring rights to this work._
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace the current copyright waiver text with the following block of HTML. (HTML is valid Markdown.)

<p xmlns:dct="http://purl.org/dc/terms/">
  <a rel="license"
     href="http://creativecommons.org/publicdomain/zero/1.0/">
    <img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" />
  </a>
  <br />
  To the extent possible under law, all contributors to this BEP
  have waived all copyright and related or neighboring rights to this BEP.
</p>

Binary file added 11/images/after-orm-implementation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 11/images/before-orm-implementation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.