Published
Edited
Aug 10, 2022
25 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { DatasetteClient } from "@ambassadors/datasette-client"
Insert cell
db = new DatasetteClient("https://sqlite-extension-examples.fly.dev/data")
Insert cell
Insert cell
db
select http_version(), http_headers('X-Name', 'Alex');
Insert cell
Insert cell
Insert cell
db
select * from snapshots;
Insert cell
Insert cell
Inputs.table(
db.sql`select
request_method,
request_url,
json_extract(timings, '$.start') as started,
response_status,
length(response_body)
from snapshots`
)
Insert cell
Insert cell
Insert cell
Insert cell
JSON.parse((await db.sql`select response_body from snapshots`)[0].response_body)
Insert cell
Insert cell
db
select
-- This version of Datasette is too old for the hip new "->>" syntax :(
json_extract(value, '$.StopId') as stop_id,
json_extract(value, '$.Description') as description,
json_extract(value, '$.Latitude') as latitude,
json_extract(value, '$.Longitude') as longitude
from snapshots
join json_each(snapshots.response_body, '$.Stops')
Insert cell
Insert cell
import {L} from "@observablehq/hello-leaflet"
Insert cell
viewof map = {
const container = html`<div style="height:600px;">`;
yield container;
const icon = L.icon({
iconUrl:
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.8.0/images/marker-icon.png"
});
const map = L.map(container).setView([33.99, -118.07], 12);
container.value = map;
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
"&copy; <a href=https://www.openstreetmap.org/copyright>OpenStreetMap</a> contributors"
}).addTo(map);

for (const stop of stops) {
L.marker([stop.latitude, stop.longitude], {
icon,
title: stop.description
}).addTo(map);
}
yield container;
}
Insert cell
Insert cell
db
select response_body
-- hint: json_each will be very useful here!
from snapshots;
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db
select * from cites;
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db
select * from christmas_suntimes;
Insert cell
Insert cell
db
select
cities.name,
cities.state,
(
strftime('%s', sunset) -
strftime('%s', sunrise)
) as daylight_seconds
from christmas_suntimes
left join cites as cities on cities.rowid = christmas_suntimes.city
order by 3 desc
limit 10;
Insert cell
Insert cell
db
select
cities.name,
cities.state,
(strftime('%s', sunset) - strftime('%s', sunrise)) as daylight_seconds
from christmas_suntimes
left join cites as cities on cities.rowid = christmas_suntimes.city
order by 3 asc
limit 10;
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more