Skip to content
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

datasette fixtures.db --get "/fixtures.json" #926

Closed
simonw opened this issue Aug 11, 2020 · 2 comments
Closed

datasette fixtures.db --get "/fixtures.json" #926

simonw opened this issue Aug 11, 2020 · 2 comments

Comments

@simonw
Copy link
Owner

simonw commented Aug 11, 2020

I can expose ALL of Datasette's functionality on the command-line (without even running a web server) by adding --get and --post options to datasette serve.

datasette fixtures.db --get "/fixtures.json"

This would instantiate the Datasette ASGI app, run a fake request for /fixtures.json through it, dump the results out to standard output and quit.

A --post option could do the same for a POST request. Treating that as a stretch goal for the moment.

@simonw
Copy link
Owner Author

simonw commented Aug 11, 2020

I partly want this so I can easily implement a better test method for the Homebrew package. The test I have right now looks like this:

https://github.com/simonw/homebrew-datasette/blob/8aa30aa183158051a987a7e3f50e7e3ee05d8ee9/Formula/datasette.rb#L125-L127

  test do
    system bin/"datasette", "--help"
  end

The Homebrew docs at https://docs.brew.sh/Formula-Cookbook#add-a-test-to-the-formula say:

We want tests that don't require any user input and test the basic functionality of the application. For example foo build-foo input.foo is a good test and (despite their widespread use) foo --version and foo --help are bad tests. However, a bad test is better than no test at all.

@simonw
Copy link
Owner Author

simonw commented Aug 12, 2020

$ datasette --get '/:memory:.json?sql=select+sqlite_version()' | jq .
{
  "database": ":memory:",
  "query_name": null,
  "rows": [
    [
      "3.32.3"
    ]
  ],
  "truncated": false,
  "columns": [
    "sqlite_version()"
  ],
  "query": {
    "sql": "select sqlite_version()",
    "params": {}
  },
  "private": false,
  "allow_execute_sql": true,
  "query_ms": 1.165628433227539
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant