Skip to content

Commit

Permalink
cleanup and autogen pk docs
Browse files Browse the repository at this point in the history
  • Loading branch information
divi255 committed Nov 21, 2019
1 parent d4e6cc6 commit 77e967b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions doc/storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,35 @@ You may use the following classes as prototypes for the own storages:
.. autoclass:: AbstractFileStorage
:members:
:show-inheritance:

Auto-generated primary keys
===========================

Both RDBMS and file storages support auto-generated primary keys. For RDBMS
keys are generated by SQL server (key is auto-incremented integer field). For
file storages, key are generated as UUIDs.

When object with null primary key field is being saved for the first time,
SmartObject tries to obtain and set primary key field from storage.

To simplify this, you may create :doc:`SmartObject factory <factory>` with
*autosave=True* argument: all objects, created by this factory, will be
auto-saved as soon as created.

.. code:: python
factory = smartobject.SmartObjectFactory(MyObjClass, autosave=True)
# the new object is automatically saved and its primary key is set from the
# storage
obj = factory.create()
Storage cleanup
===============

Sometimes storage may contain orphaned objects. To clean them, it has
*cleanup(pks)* method, where *pks* is a list of object primary keys to leave,
while all other objects will be removed.

if you use :doc:`SmartObject factory <factory>`, you may use its
*cleanup(storage_id)* method as well. The method removes all objects from the
specified storage, except the objects in factory.

0 comments on commit 77e967b

Please sign in to comment.