Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timrogers/hogql
Execute PostHog HogQL (<https://posthog.com/docs/hogql>) queries from your JavaScript code
https://github.com/timrogers/hogql
Last synced: 13 days ago
JSON representation
Execute PostHog HogQL (<https://posthog.com/docs/hogql>) queries from your JavaScript code
- Host: GitHub
- URL: https://github.com/timrogers/hogql
- Owner: timrogers
- License: mit
- Created: 2024-07-20T18:31:40.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-16T15:31:17.000Z (24 days ago)
- Last Synced: 2024-12-16T16:55:49.053Z (24 days ago)
- Language: TypeScript
- Size: 510 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# hogql
Execute PostHog [HogQL](https://posthog.com/docs/hogql) queries from your JavaScript code
## Installation
```bash
npm install --save hogql
```## Usage
### From JavaScript code
```ts
import { hogql } from 'hogql';(async () => {
const { results } = await hogql<[string, string][]>('SELECT uuid, event FROM events LIMIT 500', {
apiKey: process.env.POSTHOG_API_KEY,
projectId: process.env.POSTHOG_PROJECT_ID,
});for (const [uuid, event] of results) {
console.log(`${uuid}: ${event}`);
}
})();
```### From the command line
Run the following command, specifying your query, and the query results will be printed as JSON to STDOUT:
```bash
npx hogql "SELECT * FROM events LIMIT 10"
```As well as specifying the query, you must configure:
* a PostHog API key, using the `--posthog-api-key` option or the `POSTHOG_API_KEY` environment variable
* the PostHog project ID, using the `--posthog-project-id` option or the `POSTHOG_PROJECT_ID` environment variableYou may also configure:
* the PostHog base URL, if required, using the `--posthog-base-url` option or the `POSTHOG_BASE_URL` environment variable. Defaults to https://app.posthog.com.
* the format for the results. By default, an array of arrays will be logged to STDOUT as JSON, but you can set the `--return-objects` to return an array of key-value objects instead, using the column names returned by the PostHog API as keys