Skip to content

Commit

Permalink
Deployed ebe6941 with MkDocs version: 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jrycw committed Aug 4, 2024
1 parent b1915f3 commit 08e19d3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
22 changes: 10 additions & 12 deletions scenes/scene03/scene03/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ <h3 id="archivecriminalrecord">建立<code>Archive</code>及<code>CriminalRecord
<h3 id="insert-criminalrecord"><code>insert</code> <code>CriminalRecord</code></h3>
<p>我們選擇使用<a href="https://www.edgedb.com/docs/stdlib/tuple#type::std::tuple"><code>tuple</code></a>搭配<a href="https://www.edgedb.com/docs/edgeql/for#for"><code>for-loop</code></a><code>insert</code>片中出現的兩次犯罪記錄,這個模式在EdgeDB中稱為<a href="https://www.edgedb.com/docs/edgeql/for#bulk-inserts">bulk inserts</a></p>
<ul>
<li><code>with</code>區塊中,建立一個<code>records</code> <code>set</code>,裡面有兩個<code>tuple</code>代表兩次犯罪記錄。<code>tuple</code>的第一個元素為<code>ref_no</code>,而第二個元素為<code>code</code></li>
<li><code>with</code>區塊中,建立一個<code>records</code> <code>EdgeDBset</code>,裡面有兩個<code>tuple</code>代表兩次犯罪記錄。<code>tuple</code>的第一個元素為<code>ref_no</code>,而第二個元素為<code>code</code></li>
<li>接著使用<code>for-loop</code> + <code>union</code> + (<code>insert</code> <code>CriminalRecord</code>)的語法,來<code>insert</code>兩次犯罪記錄。我們可以使用<code>.0</code>來取得<code>tuple</code>的第一個元素、<code>.1</code>來取得<code>tuple</code>的第二個元素,依此類推。</li>
</ul>
<div class="language-sql highlight"><span class="filename">scenes/scene03/query.edgeql</span><pre><span></span><code><span id="__span-13-1"><a id="__codelineno-13-1" name="__codelineno-13-1" href="#__codelineno-13-1"></a><span class="o">#</span><span class="w"> </span><span class="k">end</span><span class="w"> </span><span class="n">migration</span><span class="w"> </span><span class="n">needs</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="n">be</span><span class="w"> </span><span class="n">applied</span><span class="w"> </span><span class="k">before</span><span class="w"> </span><span class="n">running</span><span class="w"> </span><span class="n">this</span><span class="w"> </span><span class="n">query</span>
Expand Down Expand Up @@ -1997,17 +1997,15 @@ <h3 id="insert-criminalrecord"><code>insert</code> <code>CriminalRecord</code></
</details>
<details class="info">
<summary>如果<code>insert</code>順序很重要</summary>
<p>由於<code>EdgeDBset</code>是無序的,所以<code>insert</code>的順序並不能保證。如果想要有確定的<code>insert</code>順序,需要搭配<code>array</code><a href="https://www.edgedb.com/docs/stdlib/range#function::std::range_unpack"><code>range_unpack</code></a>
<div class="language-sql highlight"><pre><span></span><code><span id="__span-15-1"><a id="__codelineno-15-1" name="__codelineno-15-1" href="#__codelineno-15-1"></a><span class="k">with</span><span class="w"> </span><span class="n">records</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="p">[(</span><span class="ss">&quot;CCR9314768&quot;</span><span class="p">,</span><span class="w"> </span><span class="ss">&quot;OFFNCE: A.O.A.B.H &quot;</span><span class="p">),</span><span class="w"> </span><span class="p">(</span><span class="ss">&quot;RN992317&quot;</span><span class="p">,</span><span class="w"> </span><span class="ss">&quot;CD-POD &quot;</span><span class="p">)],</span>
</span><span id="__span-15-2"><a id="__codelineno-15-2" name="__codelineno-15-2" href="#__codelineno-15-2"></a><span class="w"> </span><span class="n">record_len</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">len</span><span class="p">(</span><span class="n">records</span><span class="p">),</span>
</span><span id="__span-15-3"><a id="__codelineno-15-3" name="__codelineno-15-3" href="#__codelineno-15-3"></a><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">range_unpack</span><span class="p">(</span><span class="n">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">record_len</span><span class="p">))</span>
</span><span id="__span-15-4"><a id="__codelineno-15-4" name="__codelineno-15-4" href="#__codelineno-15-4"></a><span class="k">union</span><span class="w"> </span><span class="p">(</span><span class="k">insert</span><span class="w"> </span><span class="n">CriminalRecord</span><span class="w"> </span><span class="err">{</span>
</span><span id="__span-15-5"><a id="__codelineno-15-5" name="__codelineno-15-5" href="#__codelineno-15-5"></a><span class="w"> </span><span class="n">ref_no</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">array_get</span><span class="p">(</span><span class="n">records</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">).</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span>
</span><span id="__span-15-6"><a id="__codelineno-15-6" name="__codelineno-15-6" href="#__codelineno-15-6"></a><span class="w"> </span><span class="n">code</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">array_get</span><span class="p">(</span><span class="n">records</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">).</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span>
</span><span id="__span-15-7"><a id="__codelineno-15-7" name="__codelineno-15-7" href="#__codelineno-15-7"></a><span class="w"> </span><span class="n">involved</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">chen</span><span class="p">,</span>
</span><span id="__span-15-8"><a id="__codelineno-15-8" name="__codelineno-15-8" href="#__codelineno-15-8"></a><span class="err">}</span><span class="p">);</span>
</span></code></pre></div>
其原理是<code>array</code>是有序的,可以使用<a href="https://www.edgedb.com/docs/stdlib/array#function::std::array_get"><code>array_get</code></a>來索引,而<code>range_unpack</code>可以有序地返回<code>range</code>內的值。不過,這樣的需求應該不太常見。</p>
<p>由於<code>EdgeDBset</code>是無序的,所以<code>insert</code>的順序並不能保證。如果想要有確定的<code>insert</code>順序,可以將<code>records</code>改為<code>array</code>
<div class="language-sql highlight"><pre><span></span><code><span id="__span-15-1"><a id="__codelineno-15-1" name="__codelineno-15-1" href="#__codelineno-15-1"></a><span class="k">with</span><span class="w"> </span><span class="n">records</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="p">[(</span><span class="n">ref_no</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;CCR9314768&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">code</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;OFFNCE: A.O.A.B.H &quot;</span><span class="p">),</span><span class="w"> </span><span class="p">(</span><span class="n">ref_no</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;RN992317&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">code</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;CD-POD &quot;</span><span class="p">)],</span>
</span><span id="__span-15-2"><a id="__codelineno-15-2" name="__codelineno-15-2" href="#__codelineno-15-2"></a><span class="k">for</span><span class="w"> </span><span class="n">record</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">records</span>
</span><span id="__span-15-3"><a id="__codelineno-15-3" name="__codelineno-15-3" href="#__codelineno-15-3"></a><span class="k">union</span><span class="w"> </span><span class="p">(</span><span class="k">insert</span><span class="w"> </span><span class="n">CriminalRecord</span><span class="w"> </span><span class="err">{</span>
</span><span id="__span-15-4"><a id="__codelineno-15-4" name="__codelineno-15-4" href="#__codelineno-15-4"></a><span class="w"> </span><span class="n">ref_no</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">record</span><span class="p">.</span><span class="n">ref_no</span><span class="p">,</span>
</span><span id="__span-15-5"><a id="__codelineno-15-5" name="__codelineno-15-5" href="#__codelineno-15-5"></a><span class="w"> </span><span class="n">code</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">record</span><span class="p">.</span><span class="n">code</span><span class="p">,</span>
</span><span id="__span-15-6"><a id="__codelineno-15-6" name="__codelineno-15-6" href="#__codelineno-15-6"></a><span class="w"> </span><span class="n">involved</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">chen</span><span class="p">,</span>
</span><span id="__span-15-7"><a id="__codelineno-15-7" name="__codelineno-15-7" href="#__codelineno-15-7"></a><span class="err">}</span><span class="p">);</span>
</span></code></pre></div></p>
</details>
<h3 id="select-criminalrecord"><code>select</code> <code>CriminalRecord {**}</code></h3>
<p>我們可以使用<a href="https://www.edgedb.com/docs/edgeql/select#splats"><code>splat</code></a>的語法,來看看兩次<code>insert</code>是否成功。</p>
Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,82 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://jrycw.github.io/edgedb-ia/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/practice_time/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/initial_schema/entity/entity/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/initial_schema/person/person/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/initial_schema/place/place/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/initial_schema/time/time/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene01/scene01/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene02/scene02/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene03/scene03/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene04/scene04/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene05/scene05/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene06/scene06/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene07/scene07/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene08/scene08/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene09/scene09/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://jrycw.github.io/edgedb-ia/scenes/scene10/scene10/</loc>
<lastmod>2024-07-30</lastmod>
<lastmod>2024-08-04</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
Binary file modified sitemap.xml.gz
Binary file not shown.

0 comments on commit 08e19d3

Please sign in to comment.