Skip to content

Commit

Permalink
Update chapter-07.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
nicozanf authored Jul 7, 2024
1 parent 14a503d commit 901cc59
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions docs/chapter-07.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ not specify an image.
Notice that this way multiple records may end to reference the same
default image file and this could be a problem on a Field having
``autodelete`` enabled. When you do not want to allow duplicates for the
image field (i.e. multiple records referencing the same file) but still
image field (i.e. multiple records referencing the same file) but still
want to set a default value for the “upload” then you need a way to copy
the default file for each new record that does not specify an image.
This can be obtained using a file-like object referencing the default
Expand Down Expand Up @@ -2215,7 +2215,7 @@ In this last expression ``person.thing`` is a shortcut for
db(db.thing.owner_id == person.id)
i.e. the Set of ``thing``\ s referenced by the current ``person``. This
i.e. the Set of ``thing``\ s referenced by the current ``person``. This
syntax breaks down if the referencing table has multiple references to
the referenced table. In this case one needs to be more explicit and use
a full Query.
Expand Down Expand Up @@ -2382,7 +2382,7 @@ An example use which gives much faster selects is:

.. code:: python
rows = db(query).select(cache=(cache.ram, 3600), cacheable=True)
rows = db(query).select(cache=(cache.get, 3600), cacheable=True)
Look at `Caching selects`_, to understand what the trade-offs are.

Expand Down Expand Up @@ -2764,7 +2764,9 @@ Caching selects

The select method also takes a ``cache`` argument, which defaults to
None. For caching purposes, it should be set to a tuple where the first
element is the cache model (``cache.ram``, ``cache.disk``, etc.), and
element is the cache function with signature `(key, callback, expiration)`
(ror example ``cache.get`` assuming ``cache``
is an instance of the py4web cache object), and
the second element is the expiration time in seconds.

In the following example, you see a controller that caches a select on
Expand All @@ -2777,7 +2779,7 @@ the previous data from memory.
.. code:: python
def cache_db_select():
logs = db().select(db.log.ALL, cache=(cache.ram, 60))
logs = db().select(db.log.ALL, cache=(cache.get, 60))
return dict(logs=logs)
The ``select`` method has an optional ``cacheable`` argument, normally
Expand All @@ -2800,7 +2802,7 @@ caching:

.. code:: python
rows = db(query).select(cache=(cache.ram, 3600), cacheable=True)
rows = db(query).select(cache=(cache.get, 3600), cacheable=True)
Computed and Virtual fields
Expand Down Expand Up @@ -2871,7 +2873,7 @@ One can define a ``total_price`` virtual field as
db.item.total_price = Field.Virtual(lambda row: row.item.unit_price * row.item.quantity)
i.e. by simply defining a new field ``total_price`` to be a
i.e. by simply defining a new field ``total_price`` to be a
``Field.Virtual``. The only argument of the constructor is a function
that takes a row and returns the computed values.

Expand Down Expand Up @@ -4503,7 +4505,7 @@ The DAL can be used from any Python program simply by doing this:
from pydal import DAL, Field
db = DAL('sqlite://storage.sqlite', folder='path/to/app/databases')
i.e. import the DAL, connect and specify the folder which contains the
i.e. import the DAL, connect and specify the folder which contains the
.table files (the app/databases folder).

To access the data and its attributes we still have to define all the
Expand Down Expand Up @@ -4827,7 +4829,7 @@ globally (not thread safe):
from pydal.adapters.mysql import SQLAdapter
SQLAdapter.driver = mysqldb
i.e. ``mysqldb`` has to be *that module* with a .connect() method. You
i.e. ``mysqldb`` has to be *that module* with a .connect() method. You
can specify optional driver arguments and adapter arguments:

.. code:: python
Expand Down

0 comments on commit 901cc59

Please sign in to comment.