-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDEVELOPMENT-NOTES.html
106 lines (104 loc) · 9.28 KB
/
DEVELOPMENT-NOTES.html
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
<!DOCTYPE html>
<html>
<head>
<title>Dataset Project</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://caltechlibrary.github.io/css/site.css">
</head>
<body>
<header>
<a href="http://library.caltech.edu" title="link to Caltech Library Homepage"><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="index.html">README</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/caltechlibrary/dataset">GitHub</a></li>
</ul>
</nav>
<section>
<h1 id="developer-notes">Developer notes</h1>
<h2 id="requirements">Requirements</h2>
<p>(when compiling from source)</p>
<ul>
<li>Golang 1.23.2 or better</li>
</ul>
<h2 id="recommend">Recommend</h2>
<p>(recommended if compiling from source and for development)</p>
<ul>
<li>Bash</li>
<li>GNU Make</li>
<li>Pandoc (is used as a pre-processor to generate version.go and other
files)</li>
</ul>
<h2 id="using-the-dataset-package">Using the <em>dataset</em>
package</h2>
<ul>
<li>create/initialize collection</li>
<li>create a JSON document in a collection</li>
<li>read a JSON document</li>
<li>update a JSON document</li>
<li>delete a JSON document</li>
</ul>
<div class="sourceCode" id="cb1"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">package</span> main</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">import</span> <span class="op">(</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="st">"github.com/caltechlibrary/dataset"</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"log"</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="op">)</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">func</span> main<span class="op">()</span> <span class="op">{</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="co">// Create a collection "mystuff" inside the directory called demo</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> collection<span class="op">,</span> err <span class="op">:=</span> dataset<span class="op">.</span>InitCollection<span class="op">(</span><span class="st">"demo/mystuff.ds"</span><span class="op">,</span> <span class="st">""</span><span class="op">)</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> log<span class="op">.</span>Fatalf<span class="op">(</span><span class="st">"%s"</span><span class="op">,</span> err<span class="op">)</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> <span class="cf">defer</span> collection<span class="op">.</span>Close<span class="op">()</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> <span class="co">// Create a JSON document</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a> key <span class="op">:=</span> <span class="st">"freda"</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a> document <span class="op">:=</span> <span class="kw">map</span><span class="op">[</span><span class="dt">string</span><span class="op">]</span><span class="kw">interface</span><span class="op">{}{</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a> <span class="st">"name"</span><span class="op">:</span> <span class="st">"freda"</span><span class="op">,</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a> <span class="st">"email"</span><span class="op">:</span> <span class="st">"[email protected]"</span><span class="op">,</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">:=</span> collection<span class="op">.</span>Create<span class="op">(</span>key<span class="op">,</span> document<span class="op">);</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a> log<span class="op">.</span>Fatalf<span class="op">(</span><span class="st">"%s"</span><span class="op">,</span> err<span class="op">)</span></span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a> <span class="co">// Read a JSON document</span></span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">:=</span> collection<span class="op">.</span>Read<span class="op">(</span>key<span class="op">,</span> document<span class="op">);</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb1-26"><a href="#cb1-26" aria-hidden="true" tabindex="-1"></a> log<span class="op">.</span>Fatalf<span class="op">(</span><span class="st">"%s"</span><span class="op">,</span> err<span class="op">)</span></span>
<span id="cb1-27"><a href="#cb1-27" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-28"><a href="#cb1-28" aria-hidden="true" tabindex="-1"></a> <span class="co">// Update a JSON document</span></span>
<span id="cb1-29"><a href="#cb1-29" aria-hidden="true" tabindex="-1"></a> document<span class="op">[</span><span class="st">"email"</span><span class="op">]</span> <span class="op">=</span> <span class="st">"[email protected]"</span></span>
<span id="cb1-30"><a href="#cb1-30" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">:=</span> collection<span class="op">.</span>Update<span class="op">(</span>key<span class="op">,</span> document<span class="op">);</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb1-31"><a href="#cb1-31" aria-hidden="true" tabindex="-1"></a> log<span class="op">.</span>Fatalf<span class="op">(</span><span class="st">"%s"</span><span class="op">,</span> err<span class="op">)</span></span>
<span id="cb1-32"><a href="#cb1-32" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-33"><a href="#cb1-33" aria-hidden="true" tabindex="-1"></a> <span class="co">// Delete a JSON document</span></span>
<span id="cb1-34"><a href="#cb1-34" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">:=</span> collection<span class="op">.</span>Delete<span class="op">(</span>key<span class="op">);</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb1-35"><a href="#cb1-35" aria-hidden="true" tabindex="-1"></a> log<span class="op">.</span>Fatalf<span class="op">(</span><span class="st">"%s"</span><span class="op">,</span> err<span class="op">)</span></span>
<span id="cb1-36"><a href="#cb1-36" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-37"><a href="#cb1-37" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
<h2 id="package-requirements">package requirements</h2>
<p><em>dataset</em> is built on both Golang’s standard packages and
Caltech Library packages.</p>
<h2 id="caltech-library-packages">Caltech Library packages</h2>
<ul>
<li><a
href="https://github.com/caltechlibrary/dotpath">github.com/caltechlibrary/dotpath</a>
<ul>
<li>provides dot path style notation to reach into JSON objects</li>
</ul></li>
</ul>
</section>
<footer>
<span>© 2022 <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><a href="mailto:[email protected]">Email Us</a></span>
<span>Phone: <a href="tel:+1-626-395-3405">(626)395-3405</a></span>
</footer>
</body>
</html>