This repository was archived by the owner on Aug 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_explained.html
More file actions
454 lines (419 loc) · 45.8 KB
/
Copy pathmodel_explained.html
File metadata and controls
454 lines (419 loc) · 45.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<!DOCTYPE html>
<html lang="en">
<head>
<title>Newt -- model_explained</title>
<link rel="stylesheet" href="https://caltechlibrary.github.io/css/site.css">
<base href="./">
</head>
<body>
<header>
<a href="https://library.caltech.edu"><img src="https://caltechlibrary.github.io/assets/liblogo.gif" alt="Caltech Library logo"></a>
</header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="./">README</a></li>
<li><a href="user_manual.html">User Manual</a></li>
<li><a href="LICENSE">LICENSE</a></li>
<li><a href="INSTALL.html">INSTALL</a></li>
<li><a href="about.html">About</a></li>
<li><a href="search.html">Search</a></li>
<li><a href="https://github.com/caltechlibrary/newt">GitHub</a></li>
</ul>
</nav>
<section>
<h1 id="newts-newt-model-concept-draft">Newt’s <code>newt model</code>
(concept draft)</h1>
<h2 id="overview">Overview</h2>
<p>0 Newt model command provides an interactive way for generating and
managing your data models expressed in the Newt YAML file. It let’s you
avoid directly typing YAML. While it is interactive it is still a
command you run in your shell. It lets you adding, modify and remove
models. When modify a model it lets you add, modify and remove elements.
When you are done machine changes at the application, model or element
level you can “quit” to indicate your are done making changes. When you
quit at the models list level it will prompt you to save the changes if
you’ve made any.</p>
<p>Since your Newt application flows from your data model(s) the modeler
takes care of creating the routes and templates entries for each model
you add. Likewise takes care of cleaning up any routing or template
references previously generated the modeler when you remove a model.</p>
<p>By using <code>newt config</code>, <code>newt model</code> and
<code>newt generate</code> you can create a a deliverable Newt
application. The minimal application will depend on Postgres+PostgREST
as well as Mustache templates for rendering the human user
interface.</p>
<h2 id="running-the-newt-modeler">Running the Newt Modeler</h2>
<p>In this short tutorial we are going to create a web application that
says describes the contents of a garden. We will use the
<code>newt</code> command to configure, model and generate our
application.</p>
<h2 id="tutorial-on-the-newt-modeler">Tutorial on the Newt Modeler</h2>
<p>We will cover three steps. Creating a new “garden.yaml” file with
“config” action, modeling our garden data and generating some code.</p>
<h3 id="step-1-create-a-garden.yaml-newt-yaml-file">Step 1, create a
“garden.yaml” Newt YAML file</h3>
<p>We can create or update our “garden.yaml” using our standard
<code>newt config</code> command. For this tutorial just accept the
defaults.</p>
<pre class="shell"><code>newt config garden.yaml</code></pre>
<h3 id="step-2-defining-and-managing-models-for-garden.yaml">Step 2,
defining and managing models for “garden.yaml”</h3>
<p>The first stage of the modeler is to present a list of existing
models. It then gives you options of “add”, “remove” “modify”, “config”,
and “quit”. Launch our modeler with
<code>newt model garden.yaml</code></p>
<pre class="shell"><code>newt model garden.yaml</code></pre>
<p>By default the command <code>newt config</code> manages the
“applications” attribute in our “garden.yaml” file. It doesn’t create
any models, routes, or templates. created an “garden” model. When we use
<code>newt model</code> the models defined will then trigger the
creation of routes and templates attributes needed by the
application.</p>
<p>When you launch <code>net model</code> you are presented with a text
menu that looks like this.</p>
<pre class="shell"><code>Enter menu letter and id
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>No models have been defined yet. Let’s add one called “garden” by
press “a” key followed by enter key.</p>
<p>You should now see a prompt like below.</p>
<pre class="shell"><code>Enter model id to add:</code></pre>
<p>Type in “garden” without the quotes, then press enter key</p>
<p>Now the menu should look like this.</p>
<pre class="shell"><code>Enter menu letter and id
1: garden
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>An empty model called “garden” has been created. If we want to remove
it we would type the following ending in pressing the enter key.</p>
<pre class="shell"><code>remove garden</code></pre>
<p>At this point the menu would not show any models. Add “garden” back
so we can continue with modifying our newly created “garden” model.</p>
<p>This is what you can type as a short cut.</p>
<pre class="shell"><code>add garden</code></pre>
<p>You should see this menu again.</p>
<pre class="shell"><code>Enter menu letter and id
1: garden
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>We now ready to “modify” our model. You’ll see the theme of
<code>Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code>
through out the modeling process targeting the specific level you’re
refining.</p>
<p>Type the following at this menu.</p>
<pre class="shell"><code>modify garden</code></pre>
<p>This will take you to a new menu focused on managing the garden
model.</p>
<pre class="shell"><code>Enter menu letter to manage model
1: Model Id: garden
2: Descriptions: ... description of "garden" goes here ...
3: Elements: identifier
Menu: model [d]escription, [e]lements, [q]uit (making changes)</code></pre>
<p>This menu is slightly different because we have different types of
parameters that can be modify in our model. An individual model contains
an identifier. This you can’t change but is displayed so you know what
you are modifying. At the “Menu”: line we see that we have choices of
description, element and quit. Let’s modify the description first to be
something less generatic.</p>
<p>Type the following followed by pressing the enter key.</p>
<pre class="shell"><code>d This is a model of my garden</code></pre>
<p>Notice that I typed “d” instead of the whole word “description”. This
short cut can be used through the modeler where a single letter is
indicated by square brackets, <code>[d]escription</code> would mean you
could type “d”, <code>[q]uit</code> would mean you can type “q” instead
of “quit”.</p>
<p>The updated menu should look like this.</p>
<pre class="shell"><code>Enter menu letter to manage model
1: Model Id: garden
2: Descriptions: This is a model of my garden
3: Elements: identifier
Menu: model [d]escription, [e]lements, [q]uit (making changes)</code></pre>
<p>When a model is added one element is created as an example. That
element is called “identifier” which stands for object identifier. To
manage objects we a specific unique key to access them. That is what an
object identifier provides. At the SQL level this is analogous to a
primary key.</p>
<p>Elements are the specific data held and managed by your model. You
can think of them as the columns in a spreadsheet. We many have lots of
objects just as you can have lots of rows in a spreadsheet.</p>
<p>Let’s modify our element list. The first thing we’ll do is get rid of
“identifier” and create a new primary key called “garden_id”.</p>
<p>Type the letter “e” and press enter.</p>
<p>You should see this new menu.</p>
<pre class="shell"><code>Enter menu letter and id
1: identifier
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>This is a list of our model’s elements. We can remove the
“identifier” by typing the following followed by pressing the enter
key.</p>
<pre class="shell"><code>r identifier</code></pre>
<p>The list should now look like</p>
<pre class="shell"><code>Enter menu letter and id
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>Now let’s add our “garden_id” by typing the following and then
pressing the enter key</p>
<pre class="shell"><code>a garden_id</code></pre>
<p>The menu now should look like</p>
<pre class="shell"><code>Enter menu letter and id
1: garden_id
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>We are ready to modify our garden_id and make it the primary key.
Type the following and press the entery key.</p>
<pre><code>m garden_id</code></pre>
<p>This takes us to the element menu.</p>
<pre><code>Select menu item to model properties
1: id garden_id
2: type input
3: pattern
4: attributes name
title
5: primary key false
Menu [t]ype, [p]attern, [a]ttributes, [o]bject id flag, [q]uit (making changes)</code></pre>
<p>Like the model menu we have options to modify the common properties,
e.g. type, pattern, and importantly primary key via
<code>[o]object id flag</code>.</p>
<p>Enter the letter “o” and press enter. Notice how number five changes.
The menu should now look like</p>
<pre class="shell"><code>Select menu item to model properties
1: id garden_id
2: type input
3: pattern
4: attributes name
title
5: is object id true
Menu [t]ype, [p]attern, [a]ttributes, [o]bject id flag, [q]uit (making changes)</code></pre>
<p>Because is object id can be either true (on) or false (off) you are
not prompted to set its value. Now let’s take a look at attributes. You
see “name” and “title”. Name is used when this element’s HTML is
rendered. The name attribute is set by the contents of name. Similarly
the title attribute (used for hover text in a form element) is all set.
Managing an element’s attributes is done by pressing “a” and then the
enter key. You you’ve done that you should see the following.</p>
<pre class="shell"><code>Enter menu letter and id
1: name
2: title
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>Let’s change the title text to explain what garden_id is.</p>
<p>Type the following followed by pressing the enter key.</p>
<pre class="shell"><code>m title</code></pre>
<p>The menu should now show this.</p>
<pre class="shell"><code>Enter title's value:</code></pre>
<p>Enter a description of the garden_id as follows finishing by
presssing the enter key.</p>
<pre class="shell"><code>This is the unique identifier for the garden model.</code></pre>
<p>Now that we’re done changing the attributes press “q” and then the
enter key. This will take us back “up” the element level menu.</p>
<pre class="shell"><code>Select menu item to model properties
1: id garden_id
2: type input
3: pattern
4: attributes name
title
5: is object id true
Menu [t]ype, [p]attern, [a]ttributes, [o]bject id flag, [q]uit (making changes)</code></pre>
<p>Typing “q” and enter again will take us up further to the list of
elements in our model.</p>
<pre class="shell"><code>Enter menu letter and id
1: garden_id
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>Typing “q” and enter again will show us a summary of our model.</p>
<pre class="shell"><code>Enter menu letter to manage model
1: Model Id: garden
2: Descriptions: This is a model of my garden
3: Elements: garden_id
Menu: model [d]escription, [e]lements, [q]uit (making changes)</code></pre>
<p>Typing “q” and pressing enter here will take us to our list of
models.</p>
<pre class="shell"><code>Enter menu letter and id
1: garden
Menu [a]dd, [m]odify, [r]emove, [q]uit (making changes)</code></pre>
<p>Typing “q” and pressing enter one last time you should now be
prompted to save your model.</p>
<pre class="shell"><code>Save before exiting (Y/n)?</code></pre>
<p>Answer “y” and press enter.</p>
<p>This will save the Newt YAML file and bring us back to the shell
prompt. If you use the more command you can see the YAML we’ve
created.</p>
<pre class="shell"><code>more garden.yaml</code></pre>
<p>This should return something like this.</p>
<div class="sourceCode" id="cb31"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="co">#/usr/bin/env newt check</span></span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a><span class="co">#</span></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a><span class="co"># This was generated by rsdoiel on 2024-05-09 with newt version 0.0.8 8453132.</span></span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a><span class="co">#</span></span>
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true" tabindex="-1"></a><span class="fu">applications</span><span class="kw">:</span></span>
<span id="cb31-6"><a href="#cb31-6" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">router</span><span class="kw">:</span></span>
<span id="cb31-7"><a href="#cb31-7" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">port</span><span class="kw">:</span><span class="at"> </span><span class="dv">8010</span></span>
<span id="cb31-8"><a href="#cb31-8" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template_engine</span><span class="kw">:</span></span>
<span id="cb31-9"><a href="#cb31-9" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">port</span><span class="kw">:</span><span class="at"> </span><span class="dv">8011</span></span>
<span id="cb31-10"><a href="#cb31-10" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">base_dir</span><span class="kw">:</span><span class="at"> views</span></span>
<span id="cb31-11"><a href="#cb31-11" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">partials_dir</span><span class="kw">:</span><span class="at"> partials</span></span>
<span id="cb31-12"><a href="#cb31-12" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">ext_name</span><span class="kw">:</span><span class="at"> .hbs</span></span>
<span id="cb31-13"><a href="#cb31-13" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">postgres</span><span class="kw">:</span></span>
<span id="cb31-14"><a href="#cb31-14" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">port</span><span class="kw">:</span><span class="at"> </span><span class="dv">5432</span></span>
<span id="cb31-15"><a href="#cb31-15" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">dsn</span><span class="kw">:</span><span class="at"> postgres://{PGUSER}:{PGPASSWORD}@localhost:5432/garden.yaml</span></span>
<span id="cb31-16"><a href="#cb31-16" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">postgrest</span><span class="kw">:</span></span>
<span id="cb31-17"><a href="#cb31-17" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">app_path</span><span class="kw">:</span><span class="at"> postgrest</span></span>
<span id="cb31-18"><a href="#cb31-18" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">conf_path</span><span class="kw">:</span><span class="at"> postgrest.conf</span></span>
<span id="cb31-19"><a href="#cb31-19" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">port</span><span class="kw">:</span><span class="at"> </span><span class="dv">3000</span></span>
<span id="cb31-20"><a href="#cb31-20" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">enviroment</span><span class="kw">:</span></span>
<span id="cb31-21"><a href="#cb31-21" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> PGUSER</span></span>
<span id="cb31-22"><a href="#cb31-22" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> PGPASSWORD</span></span>
<span id="cb31-23"><a href="#cb31-23" aria-hidden="true" tabindex="-1"></a><span class="fu">models</span><span class="kw">:</span></span>
<span id="cb31-24"><a href="#cb31-24" 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"> garden</span></span>
<span id="cb31-25"><a href="#cb31-25" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This is a model of my garden</span></span>
<span id="cb31-26"><a href="#cb31-26" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">elements</span><span class="kw">:</span></span>
<span id="cb31-27"><a href="#cb31-27" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">type</span><span class="kw">:</span><span class="at"> text</span></span>
<span id="cb31-28"><a href="#cb31-28" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">id</span><span class="kw">:</span><span class="at"> garden_id</span></span>
<span id="cb31-29"><a href="#cb31-29" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">primary_key</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb31-30"><a href="#cb31-30" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">attributes</span><span class="kw">:</span></span>
<span id="cb31-31"><a href="#cb31-31" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> garden_id</span></span>
<span id="cb31-32"><a href="#cb31-32" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">title</span><span class="kw">:</span><span class="at"> This is the unique identifier for the garden model.</span></span>
<span id="cb31-33"><a href="#cb31-33" 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="cb31-34"><a href="#cb31-34" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">type</span><span class="kw">:</span><span class="at"> text</span></span>
<span id="cb31-35"><a href="#cb31-35" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">id</span><span class="kw">:</span><span class="at"> description</span></span>
<span id="cb31-36"><a href="#cb31-36" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">attrbiutes</span><span class="kw">:</span></span>
<span id="cb31-37"><a href="#cb31-37" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> description</span></span>
<span id="cb31-38"><a href="#cb31-38" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">title</span><span class="kw">:</span><span class="at"> This holds a description of hte garden element</span></span>
<span id="cb31-39"><a href="#cb31-39" 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="cb31-40"><a href="#cb31-40" aria-hidden="true" tabindex="-1"></a><span class="fu">routes</span><span class="kw">:</span></span>
<span id="cb31-41"><a href="#cb31-41" 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"> garden_create</span></span>
<span id="cb31-42"><a href="#cb31-42" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> GET /garden_create</span></span>
<span id="cb31-43"><a href="#cb31-43" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Handle retrieving the webform for garden create</span></span>
<span id="cb31-44"><a href="#cb31-44" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-45"><a href="#cb31-45" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_create</span></span>
<span id="cb31-46"><a href="#cb31-46" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Display a garden for create</span></span>
<span id="cb31-47"><a href="#cb31-47" 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"> garden_create</span></span>
<span id="cb31-48"><a href="#cb31-48" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> POST /garden_create</span></span>
<span id="cb31-49"><a href="#cb31-49" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Handle form submission for garden create</span></span>
<span id="cb31-50"><a href="#cb31-50" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-51"><a href="#cb31-51" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:3000/rpc/garden_create</span></span>
<span id="cb31-52"><a href="#cb31-52" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Access PostgREST API for garden create</span></span>
<span id="cb31-53"><a href="#cb31-53" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_create_response</span></span>
<span id="cb31-54"><a href="#cb31-54" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This is an result template for garden create</span></span>
<span id="cb31-55"><a href="#cb31-55" 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"> garden_update</span></span>
<span id="cb31-56"><a href="#cb31-56" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> GET /garden_update/{garden_id}</span></span>
<span id="cb31-57"><a href="#cb31-57" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Handle retrieving the webform for garden update</span></span>
<span id="cb31-58"><a href="#cb31-58" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-59"><a href="#cb31-59" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> GET http://localhost:3000/rpc/garden_read/{garden_id}</span></span>
<span id="cb31-60"><a href="#cb31-60" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Retrieve garden from PostgREST API before update</span></span>
<span id="cb31-61"><a href="#cb31-61" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_update</span></span>
<span id="cb31-62"><a href="#cb31-62" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Display a garden for update</span></span>
<span id="cb31-63"><a href="#cb31-63" 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"> garden_update</span></span>
<span id="cb31-64"><a href="#cb31-64" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> POST /garden_update</span></span>
<span id="cb31-65"><a href="#cb31-65" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Handle form submission for garden update</span></span>
<span id="cb31-66"><a href="#cb31-66" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-67"><a href="#cb31-67" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> PUT http://localhost:3000/rpc/garden_update/{garden_id}</span></span>
<span id="cb31-68"><a href="#cb31-68" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Access PostgREST API for garden update</span></span>
<span id="cb31-69"><a href="#cb31-69" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_update_response</span></span>
<span id="cb31-70"><a href="#cb31-70" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This is an result template for garden update</span></span>
<span id="cb31-71"><a href="#cb31-71" 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"> garden_delete</span></span>
<span id="cb31-72"><a href="#cb31-72" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> GET /garden_delete/{garden_id}</span></span>
<span id="cb31-73"><a href="#cb31-73" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Handle retrieving the webform for garden delete</span></span>
<span id="cb31-74"><a href="#cb31-74" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-75"><a href="#cb31-75" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> GET http://localhost:3000/rpc/garden_read/{garden_id}</span></span>
<span id="cb31-76"><a href="#cb31-76" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Retrieve garden from PostgREST API before delete</span></span>
<span id="cb31-77"><a href="#cb31-77" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_delete</span></span>
<span id="cb31-78"><a href="#cb31-78" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Display a garden for delete</span></span>
<span id="cb31-79"><a href="#cb31-79" 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"> garden_delete</span></span>
<span id="cb31-80"><a href="#cb31-80" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> POST /garden_delete</span></span>
<span id="cb31-81"><a href="#cb31-81" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Handle form submission for garden delete</span></span>
<span id="cb31-82"><a href="#cb31-82" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-83"><a href="#cb31-83" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> DELETE http://localhost:3000/rpc/garden_delete/{garden_id}</span></span>
<span id="cb31-84"><a href="#cb31-84" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Access PostgREST API for garden delete</span></span>
<span id="cb31-85"><a href="#cb31-85" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_delete_response</span></span>
<span id="cb31-86"><a href="#cb31-86" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This is an result template for garden delete</span></span>
<span id="cb31-87"><a href="#cb31-87" 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"> garden_read</span></span>
<span id="cb31-88"><a href="#cb31-88" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> POST /garden_read</span></span>
<span id="cb31-89"><a href="#cb31-89" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Retrieve object(s) for garden read</span></span>
<span id="cb31-90"><a href="#cb31-90" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-91"><a href="#cb31-91" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> GET http://localhost:3000/rpc/garden_read/{garden_id}</span></span>
<span id="cb31-92"><a href="#cb31-92" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Access PostgREST API for garden read</span></span>
<span id="cb31-93"><a href="#cb31-93" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_read</span></span>
<span id="cb31-94"><a href="#cb31-94" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This template handles garden read</span></span>
<span id="cb31-95"><a href="#cb31-95" 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"> garden_list</span></span>
<span id="cb31-96"><a href="#cb31-96" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> POST /garden_list</span></span>
<span id="cb31-97"><a href="#cb31-97" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Retrieve object(s) for garden list</span></span>
<span id="cb31-98"><a href="#cb31-98" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-99"><a href="#cb31-99" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> GET http://localhost:3000/rpc/garden_list</span></span>
<span id="cb31-100"><a href="#cb31-100" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Access PostgREST API for garden list</span></span>
<span id="cb31-101"><a href="#cb31-101" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_list</span></span>
<span id="cb31-102"><a href="#cb31-102" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This template handles garden list</span></span>
<span id="cb31-103"><a href="#cb31-103" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Retrieve object(s) for garden read</span></span>
<span id="cb31-104"><a href="#cb31-104" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-105"><a href="#cb31-105" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> GET http://localhost:3000/rpc/garden_read/{garden_id}</span></span>
<span id="cb31-106"><a href="#cb31-106" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Access PostgREST API for garden read</span></span>
<span id="cb31-107"><a href="#cb31-107" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_read</span></span>
<span id="cb31-108"><a href="#cb31-108" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This template handles garden read</span></span>
<span id="cb31-109"><a href="#cb31-109" 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"> garden_list</span></span>
<span id="cb31-110"><a href="#cb31-110" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> POST /garden_list</span></span>
<span id="cb31-111"><a href="#cb31-111" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Retrieve object(s) for garden list</span></span>
<span id="cb31-112"><a href="#cb31-112" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">pipeline</span><span class="kw">:</span></span>
<span id="cb31-113"><a href="#cb31-113" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> GET http://localhost:3000/rpc/garden_list</span></span>
<span id="cb31-114"><a href="#cb31-114" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Access PostgREST API for garden list</span></span>
<span id="cb31-115"><a href="#cb31-115" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">service</span><span class="kw">:</span><span class="at"> POST http://localhost:8011/garden_list</span></span>
<span id="cb31-116"><a href="#cb31-116" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This template handles garden list</span></span>
<span id="cb31-117"><a href="#cb31-117" aria-hidden="true" tabindex="-1"></a><span class="fu">templates</span><span class="kw">:</span></span>
<span id="cb31-118"><a href="#cb31-118" 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"> garden_create</span></span>
<span id="cb31-119"><a href="#cb31-119" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_create</span></span>
<span id="cb31-120"><a href="#cb31-120" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_create_form</span></span>
<span id="cb31-121"><a href="#cb31-121" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Display a garden for create</span></span>
<span id="cb31-122"><a href="#cb31-122" 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"> garden_create</span></span>
<span id="cb31-123"><a href="#cb31-123" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_create_response</span></span>
<span id="cb31-124"><a href="#cb31-124" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_create_response</span></span>
<span id="cb31-125"><a href="#cb31-125" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This is an result template for garden create</span></span>
<span id="cb31-126"><a href="#cb31-126" 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"> garden_update</span></span>
<span id="cb31-127"><a href="#cb31-127" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_update</span></span>
<span id="cb31-128"><a href="#cb31-128" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_update_form</span></span>
<span id="cb31-129"><a href="#cb31-129" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Display a garden for update</span></span>
<span id="cb31-130"><a href="#cb31-130" 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"> garden_update</span></span>
<span id="cb31-131"><a href="#cb31-131" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_update_response</span></span>
<span id="cb31-132"><a href="#cb31-132" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_update_response</span></span>
<span id="cb31-133"><a href="#cb31-133" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This is an result template for garden update</span></span>
<span id="cb31-134"><a href="#cb31-134" 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"> garden_delete</span></span>
<span id="cb31-135"><a href="#cb31-135" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_delete</span></span>
<span id="cb31-136"><a href="#cb31-136" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_delete_form</span></span>
<span id="cb31-137"><a href="#cb31-137" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> Display a garden for delete</span></span>
<span id="cb31-138"><a href="#cb31-138" 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"> garden_delete</span></span>
<span id="cb31-139"><a href="#cb31-139" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_delete_response</span></span>
<span id="cb31-140"><a href="#cb31-140" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_delete_response</span></span>
<span id="cb31-141"><a href="#cb31-141" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This is an result template for garden delete</span></span>
<span id="cb31-142"><a href="#cb31-142" 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"> garden_read</span></span>
<span id="cb31-143"><a href="#cb31-143" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_read</span></span>
<span id="cb31-144"><a href="#cb31-144" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_read</span></span>
<span id="cb31-145"><a href="#cb31-145" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This template handles garden read</span></span>
<span id="cb31-146"><a href="#cb31-146" 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"> garden_list</span></span>
<span id="cb31-147"><a href="#cb31-147" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">request</span><span class="kw">:</span><span class="at"> /garden_list</span></span>
<span id="cb31-148"><a href="#cb31-148" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">template</span><span class="kw">:</span><span class="at"> garden_list</span></span>
<span id="cb31-149"><a href="#cb31-149" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">description</span><span class="kw">:</span><span class="at"> This template handles garden list</span></span></code></pre></div>
<p>While the application would not be useful yet, our garden model only
contains an id, we could generate our application’s SQL, PostgREST
configuration and Mustache templates with
<code>newt generate garden.yaml</code>.</p>
<p>As an exercise I recommend adding additionals elements to our garden
model such as plant, location and then regenerate the code an notice
what changes in the setup.sql and model.sql as well as in our mustache
templates.</p>
<h3 id="step-3.-generate-some-code">Step 3. Generate some code</h3>
<p>This last step is one short command but it will generate many files.
Type the following command at the shell prompt.</p>
<pre class="shell"><code>newt generate garden.yaml</code></pre>
<p>This will generate the following files.</p>
<pre><code>postgrest.conf
setup.sql
models.sql
validator.ts
views/garden_create_form.hbs
views/garden_create_response.hbs
views/garden_delete_response.hbs
views/garden_read.hbs
views/garden_update_response.hbs</code></pre>
</section>
<footer>
<span><h1><A href="http://caltech.edu">Caltech</a></h1></span>
<span>© 2024 <a href="https://www.library.caltech.edu/copyright">Caltech library</a></span>
<address>1200 E California Blvd, Mail Code 1-32, Pasadena, CA 91125-3200</address>
<span>Phone: <a href="tel:+1-626-395-3405">(626)395-3405</a></span>
<span><a href="mailto:library@caltech.edu">Email Us</a></span>
<a class="cl-hide" href="sitemap.xml">Site Map</a>
</footer>
</body>
</html>