Skip to content

Commit 128b22c

Browse files
committed
📝 Db querying docs added to readme
1 parent 9980587 commit 128b22c

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,54 @@
1313
## Installation
1414

1515
.Net CLI
16+
1617
```
1718
dotnet add package Notion.Net
1819
```
1920

2021
## Usage
2122

2223
> Before getting started, you need to [create an integration](https://www.notion.com/my-integrations) and find the token. You can learn more about authorization [here](https://developers.notion.com/docs/authorization).
23-
24+
2425
Import and initialize the client using the integration token created above.
25-
26+
2627
![image](https://user-images.githubusercontent.com/18693839/119268863-79925b00-bc12-11eb-92cb-d5a9a8c57fdc.png)
2728

2829
Make A request to any Endpoint. For example you can call below to fetch the paginated list of users.
29-
30+
3031
![image](https://user-images.githubusercontent.com/18693839/119268924-ae9ead80-bc12-11eb-9d1a-925267896d9e.png)
3132

33+
### Querying a database
34+
35+
After you initialized your client and got an id of a database, you can query it for any contained pages. You can add filters and sorts to your request. Here is a simple example:
36+
37+
```C#
38+
// Date filter for page property called "When"
39+
var dateFilter = new DateFilter("When", onOrAfter: DateTime.Now);
40+
41+
var queryParams = new DatabasesQueryParameters { Filter = dateFilter };
42+
var pages = await client.Databases.QueryAsync(databaseId, queryParams);
43+
```
3244

45+
Filters constructors contain all possible filter conditions, but you need to choose only condition per filter, all other should be `null`. So, for example this code would not filter by 2 conditions as one might expect:
46+
47+
```C#
48+
var filter = new TextFilter("Name", startsWith: "Mr", contains: "John"); // WRONG FILTER USAGE
49+
50+
```
51+
52+
To use complex filters, use class `CompoundFilter`. It allows adding many filters and even nesting compound filters into each other (it works as filter group in Notion interface). Here is an example of filter that would return pages that were due in past month AND either had a certain assignee OR had high urgency:
53+
54+
```C#
55+
var selectFilter = new SelectFilter("Urgency", equal: "High");
56+
var assigneeFilter = new PeopleFilter("Assignee", contains: "some-uuid");
57+
var dateFilter = new DateFilter("Due", pastMonth: new Dictionary<string, object>());
58+
59+
var orGroup = new List<Filter> { assigneeFilter, selectFilter };
60+
var complexFiler = new CompoundFilter(
61+
and: new List<Filter> { dateFilter, new CompoundFilter(or: orGroup) }
62+
);
63+
```
3364

3465
## Contribution Guideline
3566

0 commit comments

Comments
 (0)