-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documented JavaScript variables on different templates made available for plugins #1565
Comments
This should aim to be as consistent as possible with the various arguments to hooks on https://docs.datasette.io/en/stable/plugin_hooks.html |
The table page should expose the query both with and without the select id, ACCESS_TYP, UNIT_ID, UNIT_NAME, SUID_NMA, AGNCY_ID, AGNCY_NAME, AGNCY_LEV,
AGNCY_TYP, AGNCY_WEB, LAYER, MNG_AG_ID, MNG_AGENCY, MNG_AG_LEV, MNG_AG_TYP,
PARK_URL, COUNTY, ACRES, LABEL_NAME, YR_EST, DES_TP, GAP_STS, geometry
from CPAD_2020a_Units where "AGNCY_LEV" = :p0 order by id limit 101 But I actually wanted to run a |
I want to get this into Datasette 0.60 - #1566 - it's a small change that can unlock a lot of potential. |
This should also expose the JSON API endpoints used to execute SQL against this database. |
... huh, it could even expose a JavaScript function that can be called to execute a SQL query. datasette.query("select * from blah").then(...) Maybe it takes an optional second argument that specifies the database - defaulting to the one for the current page. |
Or... rows = await datasette.query`select * from searchable where id > ${id}`; And it knows how to turn that into a parameterized call using tagged template literals. |
Quick prototype of that tagged template function query(pieces, ...parameters) {
var qs = new URLSearchParams();
var sql = pieces[0];
parameters.forEach((param, i) => {
sql += `:p${i}${pieces[i + 1]}`;
qs.append(`p${i}`, param);
});
qs.append("sql", sql);
return qs.toString();
}
var id = 4;
console.log(query`select * from ids where id > ${id}`); Outputs:
|
No way with a tagged template literal to pass an extra database name argument, so instead I need a method that returns a callable that can be used for the tagged template literal for a specific database - or the default database. This could work (bit weird looking though): var rows = await datasette.query("fixtures")`select * from foo`; |
While working on simonw/datasette-leaflet-freedraw#10 I found myself writing this atrocity to figure out the SQL query used for a specific table page:
This is obviously bad - it's very brittle, and will break if I ever change the text on that link (like localizing it for example).
Instead, I think pages like that one should have a block of script at the bottom something like this:
The text was updated successfully, but these errors were encountered: