Jaymon / prom

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

Expand Field with dbset and dbget methods #16

Closed Jaymon closed 8 years ago

Jaymon commented 8 years ago

They should act similar to fget and fset methods but be fired when the field is about to be written to the db and read from the db.

the dbset method:

def dbset(val, is_update=False, is_modified=False)
    """
    run this method right before the field is to be passed to the db to be written

    val -- mixed -- the current value the field contains
    is_update -- boolean -- True if updating, False if inserting
    is_modified -- boolean -- True if the field has been modified since last pull from db
    """
    return val

The dbget method:

def dbget(val):
    """val has just been pulled from the db, the returned val will be put into the field"""
    return val
Jaymon commented 8 years ago

set the field to return None if there is no value set for the field, this will allow me to remove hydrate

populate() should do iget()

add another class method to the orm that is the opposite of populate, the query insert and update will call this classmethod and pass in the fields, basically move Query._get_interface_fields() to the Orm, so that way the iset and iget methods are all accessed from the orm