You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/sphinx/source/class-scheduling.rst
+22-19Lines changed: 22 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -110,7 +110,7 @@ We're going to rely on the powerful guarantees of transactions to help keep all
110
110
111
111
@fdb.transactional
112
112
def add_class(tr, c):
113
-
tr[course.pack((c,))] = bytes(100)
113
+
tr[course.pack((c,))] = fdb.tuple.pack((100,))
114
114
115
115
:py:func:`@fdb.transactional <fdb.transactional>` is a Python decorator that makes a normal function a transactional function. All functions decorated this way *need to have a parameter named* ``tr``. This parameter is passed the transaction that the function should use to do reads and writes.
116
116
@@ -180,7 +180,7 @@ We finally get to the crucial function. A student has decided on a class (by nam
180
180
@fdb.transactional
181
181
def signup(tr, s, c):
182
182
rec = attends.pack((s, c))
183
-
tr[rec] = ''
183
+
tr[rec] = b''
184
184
185
185
We simply insert the appropriate record (with a blank value).
186
186
@@ -212,7 +212,7 @@ Let's go back to the data model. Remember that we stored the number of seats in
212
212
@fdb.transactional
213
213
defavailable_classes(tr):
214
214
return [course.unpack(k)[0] for k, v in tr[course.range(())]
215
-
ifint(v)]
215
+
iffdb.tuple.unpack(v)[0]]
216
216
217
217
This is easy -- we simply add a condition to check that the value is non-zero. Let's check out ``signup`` next:
218
218
@@ -224,11 +224,11 @@ This is easy -- we simply add a condition to check that the value is non-zero. L
We now have to check that we aren't already signed up, since we don't want a double sign up to decrease the number of seats twice. Then we look up how many seats are left to make sure there is a seat remaining so we don't push the counter into the negative. If there is a seat remaining, we decrement the counter.
234
234
@@ -259,7 +259,7 @@ Let's finish up the limited seats feature by modifying the drop function:
259
259
defdrop(tr, s, c):
260
260
rec = attends.pack((s, c))
261
261
ifnot tr[rec].present(): return# not taking this class
This case is easier than signup because there are no constraints we can hit. We just need to make sure the student is in the class and to "give back" one seat when the student drops.
@@ -277,14 +277,14 @@ Of course, as soon as our new version of the system goes live, we hear of a tric
Fortunately, we decided on a data model that keeps all of the attending records for a single student together. With this approach, we can use a single range read in the ``attends`` subspace to retrieve all the classes that a student is signed up for. We simply throw an exception if the number of classes has reached the limit of five.
0 commit comments