const groupBy = key => array =>
array.reduce((objectsByKeyValue, obj) => {
const value = obj[key];
objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
return objectsByKeyValue;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* If argument is a string, try to parse as JSON. | |
* Otherwise return null. | |
*/ | |
export function parseOrNull(raw: unknown) { | |
if (!raw) return null | |
if (typeof raw === 'string') { | |
try { | |
return JSON.parse(raw) |
On the most basic level, the way we learned to query through a table in one of our databases is pretty simple.
The SQL SELECT
statement allows us to search through a table and return a custom results table with whatever columns/groupings/operations we specified in our query.
SELECT * FROM movies WHERE rottentomatoes > 85 AND lead_actor like 'Kevin Spacey';
Unfortunately, sometimes the queries need an added level of complexity and a simple statement like the one above wont do the trick. Here are two scenarios where we need to add some intricacy to our SQL statement in order to perform a sufficient query:
- We want to query for consistencies between two separate tables that are connected through a reference key.