simonw / datasette

An open source multi-tool for exploring and publishing data
https://datasette.io
Apache License 2.0
9.1k stars 649 forks source link

Question: Access to immutable database-path #758

Open clausjuhl opened 4 years ago

clausjuhl commented 4 years ago

Hi Simon

Is there anywhere in the app-context where one can access the hashed urlpath of the database? Currently it's included in the template-context (databases[0]["path") when rendering urls of the database (eg. /db-44b06v9/cases...), but where can I find the hashed url when rendering the index-page? I'm trying to avoid redirects. Thanks!

simonw commented 4 years ago

Thanks for the suggestion! I'll add this.

simonw commented 4 years ago

It's interesting to hear from someone who's using this feature - I'm considering moving it out into a plugin #647.

simonw commented 4 years ago

https://latest.datasette.io/.json currently returns:

{
  "fixtures": {
    "name": "fixtures",
    "hash": "87b3f2c55dfb81ff1452dd306c2623fa5550b90982cfa32bad404c4d8bbedde2",
    "color": "87b3f2",
    "path": "/fixtures",
    "tables_and_views_truncated": [

I published fixtures.db here like this:

datasette publish cloudrun fixtures.db --service datasette-hash-urls --extra-options '--config hash_urls:1'

https://datasette-hash-urls-j7hipcg4aq-uw.a.run.app/.json

{
  "fixtures": {
    "name": "fixtures",
    "hash": "bda7daa889c23f9a8f06e46d7d280dd423c76275e9593c4c1cad7c53b19032fe",
    "color": "bda7da",
    "path": "/fixtures-bda7daa",
simonw commented 4 years ago

But... https://datasette-hash-urls-j7hipcg4aq-uw.a.run.app/fixtures-bda7daa.json doesn't expose that hash:

{
  "database": "fixtures",
  "size": 258048,
  "tables": [
    {
      "name": "123_starts_with_digits",

Likewise https://datasette-hash-urls-j7hipcg4aq-uw.a.run.app/fixtures-bda7daa/complex_foreign_keys.json

{
  "database": "fixtures",
  "table": "complex_foreign_keys",
  "is_view": false,
  "human_description_en": "",
  "rows": [
    [
      "1",
      "1",
      "2",
      "1"
    ]
  ],

And https://datasette-hash-urls-j7hipcg4aq-uw.a.run.app/fixtures-bda7daa/complex_foreign_keys/1.json

{
  "database": "fixtures",
  "table": "complex_foreign_keys",
  "rows": [
simonw commented 4 years ago

@clausjuhl do you have any thoughts on what would be most useful for you in these JSON responses? The full /databasename-hash path, just the 7 character hash, or something else?

clausjuhl commented 4 years ago

@simonw I would prefer just the 7 character hash. No need to make the urls any longer than they need to be :)