Skip to content

Commit

Permalink
📝 Add more docs for query hub
Browse files Browse the repository at this point in the history
  • Loading branch information
julien040 committed Oct 27, 2024
1 parent 0be92c0 commit 1ad6de1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions website/src/content/docs/docs/usage/query-hub.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,58 @@ anyquery run hello_world

Anyquery will take care of asking you for the necessary information to run the query.

You can also run a query from an https URL, or from a local file. For example, to run a query from a URL:

```bash
# Run a query from an https URL
anyquery run https://raw.githubusercontent.com/julien040/anyquery/main/queries/github_stars_per_day.sql
# Run a query from a local file
anyquery run ./queries/github_stars_per_day.sql
```

## Contributing

By contributing to the Query Hub, you can help others answer their data questions, thank you for your help! Queries start with a top-level comment that describes what the query does in TOML. Here is an example:

```sql
/*
title = "GitHub Stars per day"
description = "Discover the number of stars per day for a given repository ordered by date (recent first)"
plugins = ["github"]
author = "julien040"
tags = ["github", "stars", "statistics"]
arguments = [
{title="repository", display_title = "Repository name (owner/repo format)", type="string", description="The repository to fetch stars from (owner/repo)", regex="^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$"}
]
*/
SELECT * FROM my_table(@repository)
```

Here is an overview of the fields you can use in the top-level comment:
- `title`: The title of the query. Often, it's formatted as a question.
- `description`: A short description of what the query does to help users find it in the Query Hub.
- `plugins`: An array of plugins that the query uses.
- `author`: The github username of the author.
- `tags`: An array of tags to help users find the query.
- `arguments`: An array of arguments that the query needs to run. Each argument is an object with the following fields:
- `title`: The title of the argument.
- `display_title`: The title of the argument displayed to the user.
- `type`: The type of the argument. It can be `string`, `int`, `float` and `bool`.
- `description`: A description of the argument.
- `regex`: A regex to validate the argument.


Each argument in the `arguments` array will be asked to the user when running the query. They will be passed to the query as named parameters. You can specify them in the query using the `@` symbol followed by the argument name.

```sql
SELECT * FROM my_table(@repository)
```

## Reference

You can find the full documentation of the `anyquery run` command [here](/docs/reference/commands/anyquery_run).

0 comments on commit 1ad6de1

Please sign in to comment.