Source

zorm /

Filename Size Date modified Message
doc
zorm
63 B
502 B
1.7 KB
427 B
2.9 KB
314 B
60 B

Allows for automatic attributes based on table columns.

Syntax:

from autumn.model import Model
class MyModel(Model):
    pass

# Create new instance using args based on the order of columns
m = MyModel(1, 'A string')

# Or using kwargs
m = MyModel(field=1, text='A string')

# Saving inserts into the database (assuming it validates [see below])
m.save()

# Updating attributes
m.field = 123

# Updates database record
m.save()

# Deleting removes from the database
m.delete()

# Purely saving with an improper value, checked against
# Model.Meta.validations[field_name] will raise Model.ValidationError
m = MyModel(field=0)

# 'ValidationError: Improper value "0" for "field"'
m.save()

# Retrieval is simple using Model.get
# Returns a Query object that can be sliced
MyModel.get()

# Returns a MyModel object with an id of 7
m = MyModel.get(7)

# Limits the query results using SQL's LIMIT clause
# Returns a list of MyModel objects
m = MyModel.get()[:5]   # LIMIT 0, 5
m = MyModel.get()[10:15] # LIMIT 10, 5

# We can get all objects by slicing, using list, or iterating
m = MyModel.get()[:]
m = list(MyModel.get())
for m in MyModel.get():
    # do something here...

# We can where our Query
m = MyModel.get(field=1)
m = m.where(another_field=2)

# This is the same as
m = MyModel.get(field=1, another_field=2)

# Set the order by clause
m = MyModel.get(field=1).order_by('field DESC')
# Removing the second argument defaults the order to ASC
dependents:
msgpack redis-python python-libmemcached