You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-6
Original file line number
Diff line number
Diff line change
@@ -108,22 +108,24 @@ The loader will also automatically convert the value into a slug to be easily us
108
108
It's recommended to use e.g. the title of the entry to be easily searchable and readable.
109
109
**Do not use e.g. rich text fields as ids.**
110
110
111
-
### Improved types
111
+
### Filtering entries
112
112
113
-
By default PocketBase reports `number` and `boolean` fields as not required, even though the API will always return `0` and `false` respectively if no value is set.
114
-
This means that the loader will add `undefined` to the type of these fields.
115
-
If you want to enforce that these fields are always present, you can set the `improveTypes` option to `true`.
113
+
By default the loader will fetch all entries in the specified collection.
114
+
If you want to restrict the entries to a specific subset, you can use the `filter` option.
116
115
117
116
```ts
118
117
const blog =defineCollection({
119
118
loader: pocketbaseLoader({
120
119
...options,
121
-
improveTypes: true
120
+
filter: "<filter>"
122
121
})
123
122
});
124
123
```
125
124
126
-
This will remove `undefined` from the type of these fields and mark them as required.
125
+
For example, if you want to only fetch entries that are released but not deleted, you can use `"release >= @now && deleted = false"`.
126
+
This filter will be added to the PocketBase API request and will only fetch entries that match the filter.
127
+
This is in addition to the built-in filtering of the loader, which handles the incremental builds using the `updated` field.
128
+
For more information on how to use filters, check out the [PocketBase documentation](https://pocketbase.io/docs/api-records/#listsearch-records).
127
129
128
130
## Type generation
129
131
@@ -172,6 +174,23 @@ When superuser credentials are provided, the loader will **always use the remote
172
174
If you don't want to use the automatic type generation, you can also [provide your own schema manually](https://docs.astro.build/en/guides/content-collections/#defining-the-collection-schema).
173
175
This manual schema will **always override the automatic type generation**.
174
176
177
+
### Improved types
178
+
179
+
By default PocketBase reports `number` and `boolean` fields as not required, even though the API will always return `0` and `false` respectively if no value is set.
180
+
This means that the loader will add `undefined` to the type of these fields.
181
+
If you want to enforce that these fields are always present, you can set the `improveTypes` option to `true`.
182
+
183
+
```ts
184
+
const blog =defineCollection({
185
+
loader: pocketbaseLoader({
186
+
...options,
187
+
improveTypes: true
188
+
})
189
+
});
190
+
```
191
+
192
+
This will remove `undefined` from the type of these fields and mark them as required.
193
+
175
194
## All options
176
195
177
196
| Option | Type | Required | Description |
@@ -181,6 +200,7 @@ This manual schema will **always override the automatic type generation**.
181
200
|`idField`|`string`|| The field in the collection to use as unique id. Defaults to `id`. |
182
201
|`contentFields`|`string \| Array<string>`|| The field in the collection to use as content. This can also be an array of fields. |
183
202
|`updatedField`|`string`|| The field in the collection that stores the last update date of an entry. This is used for incremental builds. |
203
+
|`filter`|`string`|| Custom filter to use when fetching entries. Used to filter the entries by specific conditions. |
184
204
|`superuserCredentials`|`{ email: string, password: string }`|| The email and password of the superuser of the PocketBase instance. This is used for automatic type generation. |
185
205
|`localSchema`|`string`|| The path to a local schema file. This is used for automatic type generation. |
186
206
|`jsonSchemas`|`Record<string, z.ZodSchema>`|| A record of Zod schemas to use for type generation of `json` fields. |
* Credentials of a superuser to get full access to the PocketBase instance.
42
59
* This is required to get automatic type generation without a local schema, to access all resources even if they are not public and to fetch content of hidden fields.
* The PocketBase API does always return at least `0` or `false` as the default values, even though the fields are not marked as required in the schema.
74
91
*/
75
92
improveTypes?: boolean;
76
-
/**
77
-
* Custom filter that is applied when loading data from PocketBase.
78
-
* Valid syntax can be found in the [PocketBase documentation](https://pocketbase.io/docs/api-records/#listsearch-records)
79
-
*
80
-
* The loader will also add it's own filters for incremental builds.
81
-
* These will be added to your custom filter query.
0 commit comments