Skip to content

Commit

Permalink
Deployed d55acd1 with MkDocs version: 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jrycw committed Jul 28, 2024
1 parent 02a5c84 commit 271a9a2
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 216 deletions.
4 changes: 2 additions & 2 deletions scenes/scene01/scene01/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,8 @@ <h3 id="insert1992"><code>insert</code>此場景時間1992年</h3>
<div class="language-sql highlight"><span class="filename">scenes/scene01/query.edgeql</span><pre><span></span><code><span id="__span-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="k">insert</span><span class="w"> </span><span class="n">FuzzyTime</span><span class="w"> </span><span class="err">{</span><span class="n">fuzzy_year</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="mi">1992</span><span class="err">}</span><span class="p">;</span>
</span></code></pre></div>
<h3 id="insert"><code>insert</code>韓琛及其演員曾志偉</h3>
<p>韓琛於開頭就說出「一將功成萬骨枯」的經典句,我們將此句收錄在<code>classic_lines</code> <code>property</code>中。</p>
<p>此外,雖然<code>actors</code><code>multi link</code>,可以包括多個演員。但是我們可以使用<a href="https://www.edgedb.com/docs/stdlib/set#function::std::assert_single"><code>assert_single()</code></a>來確保最多只會接收到一個曾志偉<code>Actor object</code>。這麼一來,如果資料庫內已經有兩個<code>Actor object</code><code>name</code>都叫曾志偉時,這個query就會報錯。</p>
<div class="language-sql highlight"><span class="filename">scenes/scene01/query.edgeql</span><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="k">insert</span><span class="w"> </span><span class="n">Actor</span><span class="w"> </span><span class="err">{</span>
</span><span id="__span-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="w"> </span><span class="n">name</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;曾志偉&quot;</span><span class="p">,</span>
</span><span id="__span-3-3"><a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="w"> </span><span class="n">eng_name</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;Eric&quot;</span><span class="p">,</span>
Expand All @@ -1486,8 +1488,6 @@ <h3 id="insert"><code>insert</code>韓琛及其演員曾志偉</h3>
</span><span id="__span-3-11"><a id="__codelineno-3-11" name="__codelineno-3-11" href="#__codelineno-3-11"></a><span class="w"> </span><span class="n">actors</span><span class="w"> </span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="n">assert_single</span><span class="p">((</span><span class="k">select</span><span class="w"> </span><span class="n">Actor</span><span class="w"> </span><span class="n">filter</span><span class="w"> </span><span class="p">.</span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;曾志偉&quot;</span><span class="p">)),</span>
</span><span id="__span-3-12"><a id="__codelineno-3-12" name="__codelineno-3-12" href="#__codelineno-3-12"></a><span class="err">}</span><span class="p">;</span>
</span></code></pre></div>
<p>韓琛於開頭就說出「一將功成萬骨枯」的經典句,我們將此句收錄在<code>classic_lines</code> <code>property</code>中。</p>
<p>此外,雖然<code>actors</code><code>multi link</code>,可以包括多個演員。但是我們可以使用<a href="https://www.edgedb.com/docs/stdlib/set#function::std::assert_single"><code>assert_single()</code></a>來確保最多只會接收到一個曾志偉<code>Actor object</code>。這麼一來,如果資料庫內已經有兩個<code>Actor object</code><code>name</code>都叫曾志偉時,這個query就會報錯。</p>
<p>另一種作法是觀察想選擇的<code>object</code>是否有<code>constraint exclusive</code><code>property</code>可以作為<code>filter</code>。如果有的話,即代表我們最多只會選擇到一個<code>object</code>,此時就不需要額外使用<code>assert_single()</code>了。這裡由於<code>Actor object</code>沒有<code>constraint exclusive</code><code>property</code>,所以無法使用這個作法。</p>
<h3 id="insert_1"><code>insert</code>劉建明及其少年時期演員陳冠希</h3>
<p>語法與前面類似,留意<code>filter</code>時也可用<code>in {}</code>的寫法。
Expand Down
2 changes: 1 addition & 1 deletion scenes/scene09/_internal/query.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set global current_user_id:= (select Police filter .police_rank=PoliceRank.SP li
# --8<-- [end:test_police_rank_SP_sec1]

# --8<-- [start:test_police_rank_SP_sec2]
Insert PoliceSpy {name:= "test_police_spy_by_SP"}; # AccessPolicyError
insert PoliceSpy {name:= "test_police_spy_by_SP"}; # AccessPolicyError

select PoliceSpy;

Expand Down
2 changes: 1 addition & 1 deletion scenes/scene09/query.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ select validate_password("27149"); # {false}

set global current_user_id:= (select Police filter .police_rank=PoliceRank.SP limit 1).id;

Insert PoliceSpy {name:= "test_police_spy_by_SP"}; # AccessPolicyError
insert PoliceSpy {name:= "test_police_spy_by_SP"}; # AccessPolicyError

select PoliceSpy;

Expand Down
4 changes: 2 additions & 2 deletions scenes/scene09/scene09/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ <h5 id="policerankpoliceranksp">如果<code>PoliceRank</code>為<code>PoliceRank
<li><code>update</code><code>delete</code>會得到空<code>set</code></li>
</ul>
<p>這樣的結果符合需求一的部份要求。
<div class="language-sql highlight"><span class="filename">scenes/scene09/query.edgeql</span><pre><span></span><code><span id="__span-17-1"><a id="__codelineno-17-1" name="__codelineno-17-1" href="#__codelineno-17-1"></a><span class="k">Insert</span><span class="w"> </span><span class="n">PoliceSpy</span><span class="w"> </span><span class="err">{</span><span class="n">name</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;test_police_spy_by_SP&quot;</span><span class="err">}</span><span class="p">;</span><span class="w"> </span><span class="o">#</span><span class="w"> </span><span class="n">AccessPolicyError</span>
<div class="language-sql highlight"><span class="filename">scenes/scene09/query.edgeql</span><pre><span></span><code><span id="__span-17-1"><a id="__codelineno-17-1" name="__codelineno-17-1" href="#__codelineno-17-1"></a><span class="k">insert</span><span class="w"> </span><span class="n">PoliceSpy</span><span class="w"> </span><span class="err">{</span><span class="n">name</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;test_police_spy_by_SP&quot;</span><span class="err">}</span><span class="p">;</span><span class="w"> </span><span class="o">#</span><span class="w"> </span><span class="n">AccessPolicyError</span>
</span><span id="__span-17-2"><a id="__codelineno-17-2" name="__codelineno-17-2" href="#__codelineno-17-2"></a>
</span><span id="__span-17-3"><a id="__codelineno-17-3" name="__codelineno-17-3" href="#__codelineno-17-3"></a><span class="k">select</span><span class="w"> </span><span class="n">PoliceSpy</span><span class="p">;</span>
</span><span id="__span-17-4"><a id="__codelineno-17-4" name="__codelineno-17-4" href="#__codelineno-17-4"></a>
Expand Down Expand Up @@ -2468,7 +2468,7 @@ <h2 id="query-review">Query review</h2>
</span><span id="__span-26-9"><a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a>
</span><span id="__span-26-10"><a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="k">set</span><span class="w"> </span><span class="k">global</span><span class="w"> </span><span class="n">current_user_id</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="k">select</span><span class="w"> </span><span class="n">Police</span><span class="w"> </span><span class="n">filter</span><span class="w"> </span><span class="p">.</span><span class="n">police_rank</span><span class="o">=</span><span class="n">PoliceRank</span><span class="p">.</span><span class="n">SP</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="mi">1</span><span class="p">).</span><span class="n">id</span><span class="p">;</span>
</span><span id="__span-26-11"><a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a>
</span><span id="__span-26-12"><a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a><span class="k">Insert</span><span class="w"> </span><span class="n">PoliceSpy</span><span class="w"> </span><span class="err">{</span><span class="n">name</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;test_police_spy_by_SP&quot;</span><span class="err">}</span><span class="p">;</span><span class="w"> </span><span class="o">#</span><span class="w"> </span><span class="n">AccessPolicyError</span>
</span><span id="__span-26-12"><a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a><span class="k">insert</span><span class="w"> </span><span class="n">PoliceSpy</span><span class="w"> </span><span class="err">{</span><span class="n">name</span><span class="p">:</span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;test_police_spy_by_SP&quot;</span><span class="err">}</span><span class="p">;</span><span class="w"> </span><span class="o">#</span><span class="w"> </span><span class="n">AccessPolicyError</span>
</span><span id="__span-26-13"><a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a>
</span><span id="__span-26-14"><a id="__codelineno-26-14" name="__codelineno-26-14" href="#__codelineno-26-14"></a><span class="k">select</span><span class="w"> </span><span class="n">PoliceSpy</span><span class="p">;</span>
</span><span id="__span-26-15"><a id="__codelineno-26-15" name="__codelineno-26-15" href="#__codelineno-26-15"></a>
Expand Down
18 changes: 17 additions & 1 deletion scenes/scene10/_internal/query.edgeql
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# --8<-- [start:set_global]
insert Police {name:= "test_DCP", police_rank:=PoliceRank.DCP};
with one_dcp:= (select Police filter .police_rank=PoliceRank.DCP limit 1)
select if exists one_dcp then {
(select one_dcp.id)
} else {
(select (select (insert Police {name:= "test_DCP", police_rank:=PoliceRank.DCP})).id)
};

set global current_user_id:= (select Police filter .police_rank=PoliceRank.DCP limit 1).id;
# --8<-- [end:set_global]

Expand Down Expand Up @@ -87,6 +93,16 @@ set {
};
# --8<-- [end:update_chen2]

# --8<-- [start:set_global_after_migration]
with one_dcp:= (select Police filter .police_rank=PoliceRank.DCP limit 1)
select if exists one_dcp then {
(select one_dcp.id)
} else {
(select (select (insert Police {name:= "test_DCP", police_rank:=PoliceRank.DCP})).id)
};

set global current_user_id:= (select Police filter .police_rank=PoliceRank.DCP limit 1).id;
# --8<-- [end:set_global_after_migration]

# --8<-- [start:insert_may]
insert Character{
Expand Down
16 changes: 15 additions & 1 deletion scenes/scene10/query.edgeql
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
insert Police {name:= "test_DCP", police_rank:=PoliceRank.DCP};
with one_dcp:= (select Police filter .police_rank=PoliceRank.DCP limit 1)
select if exists one_dcp then {
(select one_dcp.id)
} else {
(select (select (insert Police {name:= "test_DCP", police_rank:=PoliceRank.DCP})).id)
};

set global current_user_id:= (select Police filter .police_rank=PoliceRank.DCP limit 1).id;

update chen
Expand Down Expand Up @@ -68,6 +74,14 @@ set {
lover:= assert_single((select Character filter .name="李心兒")),
};

with one_dcp:= (select Police filter .police_rank=PoliceRank.DCP limit 1)
select if exists one_dcp then {
(select one_dcp.id)
} else {
(select (select (insert Police {name:= "test_DCP", police_rank:=PoliceRank.DCP})).id)
};

set global current_user_id:= (select Police filter .police_rank=PoliceRank.DCP limit 1).id;

insert Character{
name:= "May",
Expand Down
Loading

0 comments on commit 271a9a2

Please sign in to comment.