-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
117 lines (117 loc) · 10.8 KB
/
index.html
File metadata and controls
117 lines (117 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>models</title>
<link rel="stylesheet" href="https://caltechlibrary.github.io/css/site.css">
<link rel="stylesheet" href="https://media.library.caltech.edu/cl-webcomponents/css/code-blocks.css">
<script type="module" src="https://media.library.caltech.edu/cl-webcomponents/copyToClipboard.js"></script>
<script type="module" src="https://media.library.caltech.edu/cl-webcomponents/footer-global.js"></script>
</head>
<body>
<header>
<a href="https://library.caltech.edu"><img src="https://media.library.caltech.edu/assets/caltechlibrary-logo.png" alt="Caltech Library logo"></a>
</header>
<a href="#main-content" class="visually-hidden">skip to main content</a>
<nav>
<ul>
<li><a href="/">All Library Apps</a></li>
<li><a href="index.html">Home</a></li>
<li><a href="LICENSE">LICENSE</a></li>
<li><a href="INSTALL.html">INSTALL</a></li>
<li><a href="user_manual.html">User Manual</a></li>
<li><a href="about.html">About</a></li>
<!-- <li><a href="search.html">Search</a></li> -->
<li><a href="https://github.com/caltechlibary/models">Code Repository</a></li>
</ul>
</nav>
<section id="main-content">
<p><a
href="https://github.com/caltechlibrary/models/blob/main/LICENSE"><img
src="https://img.shields.io/badge/License-BSD--like-lightgrey"
alt="License" /></a> <a
href="https://github.com/caltechlibrary/models/releases"><img
src="https://img.shields.io/github/v/release/caltechlibrary/models.svg?color=b44e88"
alt="Latest release" /></a></p>
<h1 id="models">models</h1>
<p>This is a Go package used to describe data models aligned with the
HTML5 data types. The model can be expressed in YAML or JSON. The YAML
(or JSON) data structure is patterned after the HTML5 form elements. A
single model can be used to generate HTML web forms or used to validate
a map that confirms to the model. In princple generators can be written
to express the model in other forms, e.g. SQL.</p>
<p>It is important to note that is not an Object Relational Mapper
(ORM). The purpose of the model package is to facilitate describing
simple data models using YAML then beable to reuse the models in other
Go based projects (e.g. <a
href="http://github.com/caltechlibrary/dataset">dataset</a>, <a
href="https://github.com/caltechlibrary/newt">Newt</a>).</p>
<p>This Go package assumes Go version 1.23.1 or better.</p>
<h1
id="oberservation-web-forms-describe-a-simple-data-structure">Oberservation:
Web forms describe a simple data structure</h1>
<p>The models package grew out of an observation that if you can define
the elements of an HTML5 web form you can also describe a simple data
model or schema. The problem is HTML5 is combersum to type, read and
work with. On the other hand it lends itself to expression in simpler
representations.</p>
<p>YAML can be used to represent a web form in a clear and concise way.
From that description you can extrapulate HTML and SQL Schema. You can
also use it as a guide to data validation for web form submissions.</p>
<p>Our common use cases.</p>
<ol type="1">
<li>Web form as YAML can be used to generate HTML web forms</li>
<li>Web form elements can be used to inferring the SQL column type</li>
<li>Web form as YAML is a guide to validating web form submissions</li>
</ol>
<h1 id="a-simple-example">A simple example</h1>
<p>A “guest book” model.</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">id</span><span class="kw">:</span><span class="at"> guest_book_entry</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">attributes</span><span class="kw">:</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">action</span><span class="kw">:</span><span class="at"> ./signbook.html</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">method</span><span class="kw">:</span><span class="at"> POST</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">x-success</span><span class="kw">:</span><span class="at"> ./thankyou.html</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">x-failure</span><span class="kw">:</span><span class="at"> ./oops.html</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="fu">elements</span><span class="kw">:</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">id</span><span class="kw">:</span><span class="at"> record_id</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">type</span><span class="kw">:</span><span class="at"> text</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pattern</span><span class="kw">:</span><span class="at"> </span><span class="kw">[</span><span class="at">a-z0</span><span class="dv">-9</span><span class="kw">]</span><span class="at">+\.[a-z0-9]+</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">attributes</span><span class="kw">:</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> record_id</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">placeholder</span><span class="kw">:</span><span class="at"> A unique record id</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">required</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">id</span><span class="kw">:</span><span class="at"> name</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">type</span><span class="kw">:</span><span class="at"> text</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">attributes</span><span class="kw">:</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> name</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">placeholder</span><span class="kw">:</span><span class="at"> E.g. Doe, Jane</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">required</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">id</span><span class="kw">:</span><span class="at"> message</span></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">type</span><span class="kw">:</span><span class="at"> text</span></span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">attributes</span><span class="kw">:</span></span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">placeholder</span><span class="kw">:</span><span class="at"> Please leave a message</span></span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> message</span></span>
<span id="cb1-26"><a href="#cb1-26" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">id</span><span class="kw">:</span><span class="at"> signed</span></span>
<span id="cb1-27"><a href="#cb1-27" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">type</span><span class="kw">:</span><span class="at"> date</span></span>
<span id="cb1-28"><a href="#cb1-28" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">attributes</span><span class="kw">:</span></span>
<span id="cb1-29"><a href="#cb1-29" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> signed</span></span>
<span id="cb1-30"><a href="#cb1-30" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">required</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span></code></pre></div>
<p>This “model” describes JSON data that might look like the
following.</p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode json"><code class="sourceCode json"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">{</span> </span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">"record_id"</span><span class="fu">:</span> <span class="st">"jane.doe"</span><span class="fu">,</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">"Doe, Jane"</span><span class="er">,</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">"signed"</span><span class="fu">:</span> <span class="st">"2024-09-10"</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="fu">}</span></span></code></pre></div>
<p>The model could be used to generate the web form and validate the
data. It implies an SQL Scheme. The model package provides the means of
working with a model and to validate the model’s content. By normalizing
your data elements to throse supported by HTML5 you also can easily
generate the code you need (e.g. HTML form or SQL scheme).</p>
<p>The package doesn’t provide the extrapolated forms but does provide
the functions and method to make it easy to build them.</p>
</section>
<footer-global></footer-global>
</body>
</html>