mirror of
https://github.com/alanorth/cgspace-notes.git
synced 2025-01-27 05:49:12 +01:00
Add notes for 2018-09-24
This commit is contained in:
@ -18,7 +18,7 @@ I’m testing the new DSpace 5.8 branch in my Ubuntu 18.04 environment and I
|
||||
" />
|
||||
<meta property="og:type" content="article" />
|
||||
<meta property="og:url" content="https://alanorth.github.io/cgspace-notes/2018-09/" /><meta property="article:published_time" content="2018-09-02T09:55:54+03:00"/>
|
||||
<meta property="article:modified_time" content="2018-09-23T16:51:17+03:00"/>
|
||||
<meta property="article:modified_time" content="2018-09-24T00:31:59+03:00"/>
|
||||
<meta name="twitter:card" content="summary"/>
|
||||
<meta name="twitter:title" content="September, 2018"/>
|
||||
<meta name="twitter:description" content="2018-09-02
|
||||
@ -41,9 +41,9 @@ I’m testing the new DSpace 5.8 branch in my Ubuntu 18.04 environment and I
|
||||
"@type": "BlogPosting",
|
||||
"headline": "September, 2018",
|
||||
"url": "https://alanorth.github.io/cgspace-notes/2018-09/",
|
||||
"wordCount": "2893",
|
||||
"wordCount": "3094",
|
||||
"datePublished": "2018-09-02T09:55:54+03:00",
|
||||
"dateModified": "2018-09-23T16:51:17+03:00",
|
||||
"dateModified": "2018-09-24T00:31:59+03:00",
|
||||
"author": {
|
||||
"@type": "Person",
|
||||
"name": "Alan Orth"
|
||||
@ -576,6 +576,40 @@ $ grep -c -E 'session_id=[A-Z0-9]{32}:ip_addr=50.116.102.77' dspace.log.2018-09-
|
||||
<li>Rename my cgspace-statistics-api to <a href="https://github.com/alanorth/dspace-statistics-api">dspace-statistics-api</a> on GitHub</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="2018-09-24">2018-09-24</h2>
|
||||
|
||||
<ul>
|
||||
<li>Trying to figure out how to get item views and downloads from SQLite in a join</li>
|
||||
<li>It appears SQLite doesn’t support <code>FULL OUTER JOIN</code> so some people on StackOverflow have emulated it with <code>LEFT JOIN</code> and <code>UNION</code>:</li>
|
||||
</ul>
|
||||
|
||||
<pre><code>> SELECT views.views, views.id, downloads.downloads, downloads.id FROM itemviews views
|
||||
LEFT JOIN itemdownloads downloads USING(id)
|
||||
UNION ALL
|
||||
SELECT views.views, views.id, downloads.downloads, downloads.id FROM itemdownloads downloads
|
||||
LEFT JOIN itemviews views USING(id)
|
||||
WHERE views.id IS NULL;
|
||||
</code></pre>
|
||||
|
||||
<ul>
|
||||
<li>This “works” but the resulting rows are kinda messy so I’d have to do extra logic in Python</li>
|
||||
<li>Maybe we can use one “items” table with defaults values and UPSERT (aka insert… on conflict … do update):</li>
|
||||
</ul>
|
||||
|
||||
<pre><code>sqlite> CREATE TABLE items(id INT PRIMARY KEY, views INT DEFAULT 0, downloads INT DEFAULT 0);
|
||||
sqlite> INSERT INTO items(id, views) VALUES(0, 52);
|
||||
sqlite> INSERT INTO items(id, downloads) VALUES(1, 171);
|
||||
sqlite> INSERT INTO items(id, downloads) VALUES(1, 176) ON CONFLICT(id) DO UPDATE SET downloads=176;
|
||||
sqlite> INSERT INTO items(id, views) VALUES(0, 78) ON CONFLICT(id) DO UPDATE SET views=78;
|
||||
sqlite> INSERT INTO items(id, views) VALUES(0, 3) ON CONFLICT(id) DO UPDATE SET downloads=3;
|
||||
sqlite> INSERT INTO items(id, views) VALUES(0, 7) ON CONFLICT(id) DO UPDATE SET downloads=excluded.views;
|
||||
</code></pre>
|
||||
|
||||
<ul>
|
||||
<li>This totally works!</li>
|
||||
<li>Note the special <code>excluded.views</code> form! See <a href="https://www.sqlite.org/lang_UPSERT.html">SQLite’s lang_UPSERT documentation</a></li>
|
||||
</ul>
|
||||
|
||||
<!-- vim: set sw=2 ts=2: -->
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user