Skip to content

Commit

Permalink
copyedit: /db
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson committed Sep 3, 2023
1 parent ef1c0dd commit ae02c7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/db/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ <h2 id="db-start">Section 18.1: Starting Point</h2>
</div>
<p class="continue">and use the <code>pytest.fixture</code> <span class="ix-entry" ix-key="decorator" markdown="1">decorator</span> (<a class="x-ref" href="../protocols/">Chapter 9</a>)
to create a database and two records:</p>
<div class="pagebreak"></div>

<div class="code-sample lang-py" title="test_db_original.py">
<div class="highlight"><pre><span></span><code><span class="nd">@pytest</span><span class="o">.</span><span class="n">fixture</span>
<span class="k">def</span> <span class="nf">db</span><span class="p">():</span>
Expand Down Expand Up @@ -515,6 +517,8 @@ <h2 id="db-start">Section 18.1: Starting Point</h2>
<p>We can now refactor our database
to use a <span class="ix-entry" ix-key="static method" markdown="1">static method</span> of the record class provided to its constructor
when it needs a key:</p>
<div class="pagebreak"></div>

<div class="code-sample lang-py" title="just_dict_refactored.py">
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">interface</span> <span class="kn">import</span> <span class="n">Database</span>

Expand Down Expand Up @@ -665,7 +669,7 @@ <h2 id="db-file">Section 18.3: A File-Backed Database</h2>
to write the entire database back to the file.
When we get a record,
we simply get it from the in-memory dictionary.</p>
<figure id="db-single-file">
<figure id="db-single-file" class="here">
<img src="./single_file.svg" alt="Using a single file"/>
<figcaption markdown="1">Figure 18.2: Saving the entire database in a single file.</figcaption>
</figure>
Expand Down Expand Up @@ -730,7 +734,7 @@ <h2 id="db-block">Section 18.4: Playing With Blocks</h2>
Since we know how many records there are in a block,
we can quickly calculate which block contains
the record with a particular sequence ID.</p>
<figure id="db-alloc">
<figure id="db-alloc" class="here">
<img src="./alloc.svg" alt="Mapping records to blocks"/>
<figcaption markdown="1">Figure 18.3: Mapping records to blocks.</figcaption>
</figure>
Expand Down
6 changes: 6 additions & 0 deletions src/db/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ and use the `pytest.fixture` [%i "decorator" %] ([%x protocols %])
to create a database and two records:
{: .continue}

<div class="pagebreak"></div>

[% inc file="test_db_original.py" keep="fixture" %]

Our first few tests are then:
Expand All @@ -84,6 +86,8 @@ We can now refactor our database
to use a [%i "static method" %] of the record class provided to its constructor
when it needs a key:

<div class="pagebreak"></div>

[% inc file="just_dict_refactored.py" %]

After a bit of refactoring,
Expand Down Expand Up @@ -181,6 +185,7 @@ we simply get it from the in-memory dictionary.
img="single_file.svg"
alt="Using a single file"
caption="Saving the entire database in a single file."
cls="here"
%]

The two helper methods we need to make this work are:
Expand Down Expand Up @@ -243,6 +248,7 @@ the record with a particular sequence ID.
img="alloc.svg"
alt="Mapping records to blocks"
caption="Mapping records to blocks."
cls="here"
%]

Let's create a new in-memory database
Expand Down

0 comments on commit ae02c7b

Please sign in to comment.