Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

readonly mode #90

Closed Jaymon closed 4 years ago

Jaymon commented 4 years ago

The base prom.model.Orm should be set up with readonly functionality, something like this:

class MyOrm(Orm):
    readonly = False

    def insert(self):
        if self.readonly:
            raise NotImplementedError("This Orm is in readonly mode")
        else:
            return super(MyOrm, self).insert()

    def update(self):
        if self.readonly:
            raise NotImplementedError("This Orm is in readonly mode")
        else:
            return super(MyOrm, self).update()

    def delete(self):
        if self.readonly:
            raise NotImplementedError("This Orm is in readonly mode")
        else:
            return super(MyOrm, self).delete()

This would allow you to do something like:

o = MyOrm()
o.readonly = True

To make sure you don't mess with the info in the db.

Jaymon commented 4 years ago

Another way to implement it:

def is_readonly(self):
    if self.readonly:
        raise NotImplementedError("This Orm is in readonly mode")
    return False

def insert(self):
   if not self.is_readonly():
       return super(MyOrm, self).insert()