|
| 1 | +# Notion plugin |
| 2 | + |
| 3 | +This plugin allows you to interact with Notion databases. You can read/insert/update/delete records in a database. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +You need [Anyquery](https://github.com/julien040/anyquery) to run this plugin. |
| 8 | + |
| 9 | +Then, install the plugin with the following command: |
| 10 | + |
| 11 | +```bash |
| 12 | +anyquery install notion |
| 13 | +``` |
| 14 | + |
| 15 | +At some point, you will be asked to provide your Notion API key. You can find it by creating an integration. |
| 16 | + |
| 17 | +### Find your Notion API key |
| 18 | + |
| 19 | +1. Go to [Notion's My Integrations page](https://www.notion.so/my-integrations). |
| 20 | +2. Click on the `+ New integration` button. |
| 21 | + |
| 22 | +  |
| 23 | +3. Fill in the form with the following information: |
| 24 | + 1. Name: Whatever you want |
| 25 | + 2. Associated workspace: The workspace you want the plugin to have access to |
| 26 | + 3. Type: Internal |
| 27 | + |
| 28 | +  |
| 29 | +4. Click on the `Save` button and on `Configure integration settings`. |
| 30 | + |
| 31 | +  |
| 32 | +5. Copy the `token` and paste it when asked by the plugin. |
| 33 | + |
| 34 | +  |
| 35 | + |
| 36 | +### Finding the database ID |
| 37 | + |
| 38 | +Once you have your API key, you need to find the database ID of the database you want to interact with. You can find it in the URL of the database. For example, if the URL of the database is `https://www.notion.so/myworkspace/My-Database-1234567890abcdef1234567890abcdef`, the database ID is `1234567890abcdef1234567890abcdef`. |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +The plugin supports all the basic SQL operations. Here are some examples: |
| 43 | + |
| 44 | +```sql |
| 45 | +SELECT * FROM notion_database; |
| 46 | + |
| 47 | +SELECT * FROM notion_database WHERE name = 'Michael'; |
| 48 | + |
| 49 | +INSERT INTO notion_database (name, age) VALUES ('Michael', 25); |
| 50 | + |
| 51 | +UPDATE notion_database SET age = 26 WHERE name = 'Michael'; |
| 52 | + |
| 53 | +DELETE FROM notion_database WHERE name = 'Michael'; |
| 54 | +``` |
| 55 | + |
| 56 | +## Known limitations |
| 57 | + |
| 58 | +- Rollup and UniqueID properties are not supported. |
| 59 | +- Due to the nature of formulas, a column can have different types depending on the row. This can lead to unexpected results when filtering records. |
| 60 | +- Because SQLite does not support arrays, the plugin will return a JSON representation of the array. For example, `["a", "b", "c"]` will be returned as `'["a", "b", "c"]'`. <br> |
| 61 | +You can then use the [JSON operator](https://www.sqlite.org/json1.html#the_and_operators) like in PostgreSQL to query the data. For example, `SELECT "Files & media" ->> '$[0]' FROM notion_database;` will return the first element of the array. |
| 62 | +- You cannot create/update files, formulas, or rollup properties. You cannot update the cover and icon properties of a page. |
| 63 | +- `DELETE FROM` operations only trash the record. You can restore it from the Notion interface. |
| 64 | +- Because SQLite does not have a `BOOLEAN` type, the plugin will return `0` for `false` and `1` for `true`. |
| 65 | +- Dates are returned as strings in the format `YYYY-MM-DDTHH:MM:SSZ`(RFC3339). If an end date is specified, it will be returned as a string in the format `YYYY-MM-DDTHH:MM:SSZ/YYYY-MM-DDTHH:MM:SSZ`. <br> |
| 66 | +When inserting/updating a date, you can specify the date as YYYY-MM-DD, DD/MM/YYYY, RFC3339, or a Unix timestamp. If you want to specify a time, you can use the format `YYYY-MM-DDTHH:MM:SSZ`. |
| 67 | +- Rate limit: Notion has a rate limit of 3 requests per second. While the plugin automatically handles retries, it may slow down the execution of your queries. |
| 68 | +For example, if you run a query that inserts 100 records, it will take at least 33 seconds to complete. And you will read at most 300 records per second. |
0 commit comments