Public
Edited
Jan 17, 2023
1 fork
Importers
Insert cell
Insert cell
db = FileAttachment("sql-murder-mystery.db").sqlite()
Insert cell
db
SELECT name FROM sqlite_schema
WHERE type ='table' AND name NOT LIKE 'sqlite_%';
Insert cell
tables
Insert cell
function convertDates(data, dateField) {
for (let row of data) {
const date = ""+row[dateField];
row[dateField] = date.slice(0, 4)+"-"+date.slice(4, 6)+"-"+date.slice(6, 8);
}

return data;
}
Insert cell
allData = {
let data = {};
for (let t of tables) {
if (t.name !== 'solution') {
data[t.name] = await db.query(`SELECT * FROM ${t.name};`)
if (t.name === 'crime_scene_report' || t.name === 'facebook_event_checkin') {
data[t.name] = convertDates(data[t.name], 'date');
} else if (t.name === 'get_fit_now_check_in') {
data[t.name] = convertDates(data[t.name], 'check_in_date');
} else if (t.name === 'get_fit_now_member') {
data[t.name] = convertDates(data[t.name], 'membership_start_date');
}
}
}

return data;
}
Insert cell
mysteryDuck = DuckDBClient.of(allData)
Insert cell
mysteryDuck
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more