Public
Edited
Sep 8, 2023
Importers
13 stars
Insert cell
Insert cell
db = new QuestDatabaseClient("https://demo.questdb.io")
Insert cell
db
SELECT
timestamp AS time,
avg(galon_price),
min(galon_price),
max(galon_price)
FROM gas_prices
SAMPLE BY 1M
Insert cell
Plot.plot({
y: {
label: "↑ galon_price"
},
marks: [
Plot.ruleY([0]),
Plot.areaY(gas_prices, {x: "time", y1: "min", y2: "max", curve: "step", fill: "#ccc"}),
Plot.line(gas_prices, {x: "time", y: "avg", curve: "step"})
]
})
Insert cell
Plot.plot({
y: {
label: "↑ tempF"
},
marks: [
Plot.ruleY([0]),
Plot.areaY(weather, {x: "time", y1: "min", y2: "max", curve: "step", fill: "#ccc"}),
Plot.line(weather, {x: "time", y: "avg", curve: "step"})
]
})
Insert cell
db
SELECT
timestamp AS time,
min(tempF),
max(tempF),
avg(tempF)
FROM weather
SAMPLE BY 1M
Insert cell
Plot.plot({
y: {
label: "↑ Hourly trips (thousands)",
transform: d => d / 1000
},
marks: [
Plot.ruleY([0]),
Plot.line(trips, {x: "time", y: "count", curve: "step"})
]
})
Insert cell
db
SELECT
pickup_datetime AS time,
count()
FROM trips
WHERE pickup_datetime IN '2018-06-01;7d'
SAMPLE BY 1h
Insert cell
Insert cell
class QuestDatabaseClient {
constructor(host) {
this.host = host;
}
async sql(strings, ...args) {
if (strings.length > 1) throw new Error("query parameters not supported");
return fetch(`${this.host}/exec?${new URLSearchParams({query: strings[0]})}`)
.then(response => response.json())
.then(formatResults);
}
}
Insert cell
async function exec(query) {
return fetch(`https://demo.questdb.io/exec?${new URLSearchParams({query})}`)
.then(response => response.json())
.then(formatResults);
}
Insert cell
function formatResults({error, columns, dataset}) {
if (error) throw new Error(error);
const rows = dataset.map(row => {
return Object.fromEntries(columns.map(({name, type}, i) => {
return [name, formatValue(row[i], type)];
}));
});
rows.columns = columns.map(({name}) => name);
return rows;
}
Insert cell
function formatValue(value, type) {
switch (type) {
case "TIMESTAMP": return new Date(value);
default: return value;
}
}
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