aleph-im / aleph-sdk-python

Python SDK library for the Aleph.im network
MIT License
3 stars 4 forks source link

Integrate ORM Approach for Enhanced Management of `POST`s #68

Open MHHukiewitz opened 10 months ago

MHHukiewitz commented 10 months ago

Problem Statement

Currently, our SDK handles messages and POSTs without utilizing an Object-Relational Mapping (ORM) approach. While this method is functional, it lacks some of the user-friendly, dynamic features that an ORM could provide.

Motivation

An ORM layer would make it easier for developers to interact with POSTs, particularly when it comes to unique functionalities like amendments and revisions. It could also pave the way for more advanced features without adding complexity to the API. The feature is already effectively implemented in the Active Record SDK and can offer insights into implementation here.

Proposed Solution

Integrate an ORM layer into the SDK for handling POSTs:

Example Use-Case

A developer wants to amend a POST. Instead of navigating through complex APIs or writing cumbersome code, they could simply execute something like:

post = await Post.find(item_hash)  # can fetch directly through HTTPS or from local cache
post.content = { "foo": "bar" }
await post.save()  # Post is now being amended

This automatically handles amendments and keeps track of past revisions.

Additional Context: Program/Instance Messages

Additionally, building on this, we can also introduce ORM behavior for PROGRAM and INSTANCE messages. There, we could directly integrate all the actions a user can execute on such VMs:

instance = Instance.find(item_hash)
if instance.errors:
    await instance.restart()  # trigger a restart
hoh commented 10 months ago

Can you display examples of the cumbersome code equivalent ?