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
<p>Links provides two special attributes for programming with HTML forms: <code>l:name</code>, which binds the value of an input field to a variable, and <code>l:onsubmit</code>, with which you can supply an expression to be evaluated when the form is submitted.</p>
<p>For example, to create a handle to the table <code>ice_cream</code> with fields <code>i</code> and <code>f</code> both of type <code>Int</code> associated with the database <code>db</code>, and bind it to the variable <code>fac_table</code>, use:</p>
629
634
630
-
<pre><code> var parlors = table "ice_cream_parlors"
635
+
<pre><code> var parlors = table "ice_cream_parlors"
631
636
with (name : String, fans : Int) from db;</code></pre>
632
637
633
638
<p>The variable <code>parlors</code> then has type <code>TableHandle((name : String, fans : Int), (name : String, fans : Int), (name : String, fans : Int))</code>. The three arguments to the <code>TableHandle</code> type constructor together identify the type of a row and its constraints (See <ahref="#Table-constraints">"Table constraints"</a>).</p>
<p>Since a table-handle in Links is different from a list, we cannot simply draw elements directly from a table as we draw them from a list. But a special form of generator accepts a table-handle as its source:</p>
640
645
641
-
<pre><code> var parlors = table "ice_cream_parlors"
646
+
<pre><code> var parlors = table "ice_cream_parlors"
<p>To enable these special features on a table field, add a <code>where</code> clause to the table expression that lists field names with the corresponding keyword. For example:</p>
715
720
716
-
<pre><code> table "people" with (id:Int, name:String, nationality:String)
721
+
<pre><code> table "people" with (id:Int, name:String, nationality:String)
717
722
where id readonly, nationality default from db</code></pre>
718
723
719
724
<p>This returns a table handle for the table <code>people</code> with fields <code>id</code> and <code>nationality</code>, where the <code>id</code> field cannot be modified through this handle, and <code>nationality</code> has a default value so giving a value is optional when modifying the table.</p>
720
725
721
726
<p>The type assigned by Links to a table handle has three fields, indicating the <i>readable</i> fields, the <i>writeable</i> fields and the <i>needed</i> fields, in that order:</p>
722
727
723
728
<pre><code> links>
724
-
var t = table "people" with (id:Int, name:String, nationality:String)
729
+
var t = table "people" with (id:Int, name:String, nationality:String)
@@ -888,7 +893,7 @@ <h2 id="Types-in-Links">Types in Links</h2>
888
893
889
894
links> [(42, "The answer"),
890
895
(7, "The number of wonders of the world")];
891
-
[(42, "The answer"), (7, "The number of wonders of the world")]
896
+
[(42, "The answer"), (7, "The number of wonders of the world")]
892
897
: [(Int, String)]</code></pre>
893
898
894
899
<p>Note that the type of an integer is Int, and the type of a string is String. The <i>pair</i><code>(42, "The answer")</code> has a type that indicates the first part of the pair is an <code>Int</code> and the second part is a <code>String</code>; this type is written <code>(Int, String)</code>.</p>
0 commit comments