Skip to main content

Things I Learned: Datasette-Enrichments: The Template Can Be The Optional Arguments

 This is a small thing, but it's going to give me a lot of utility with the enrichments I'm writing.

More than once, I've run into the need for an input argument to the enrichments I'm creating. Take the elevation enrichment for example. I'd like the user to be able to specify how long their elevation profile path should be in meters. My slop and drop method for adding an argument to rows of table data would be to simply specify a constant in my SQL query ala 

select tx_lat, tx_lng, rx_lat, rx_lng, 200 as optional_meters from qso_table

That would result in an extra column containing the number 200 on every row.

That also won't work with enrichments for the moment because the operate on filtered tables, not generic SQL queries. That was irksome. The answer though, is simple, elegant even.

For each enrichment, the user specifies their input using a template. For the elevation enrichment, the template looks like this:


but I could have just as easily typed


and now, that ',200' will give me the 200 argument I wanted to include on every row! It's that easy. I just hadn't thought through all of the tools that I had available.



Comments