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
* chore(loader): add support for custom unique identifier
* fix(parse-entry): use custom entry ID if available
* refactor(*): update custom id field logic and documentation
* build(deps): update dependencies
* fix(cleanup): use PocketBase id in cleanup function
* fix(schema): check for presence of custom id field
* chore(release): 0.5.0-custom-id-rc.1
* fix(schema): check for valid type of custom id field
* fix(parse-entry): print warning for different entries with identical id
* chore(release): 0.5.0-custom-id-rc.2
* Fix typo
---------
Co-authored-by: Kibet Ishmael <kmishmael@gmail.com>
Co-authored-by: lujoho <104842986+lujoho@users.noreply.github.com>
Copy file name to clipboardExpand all lines: README.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,25 @@ While the API only returns the filenames of these images and files, the loader w
62
62
This doesn't mean that the files are downloaded during the build process.
63
63
But you can directly use these URLs in your Astro components to display images or link to the files.
64
64
65
+
### Custom ids
66
+
67
+
By default, the loader will use the `id` field of the collection as the unique identifier.
68
+
If you want to use another field as the id, e.g. a slug of the title, you can specify this field via the `id` option.
69
+
70
+
```ts
71
+
const blog =defineCollection({
72
+
loader: pocketbaseLoader({
73
+
...options,
74
+
id: "<field-in-collection>"
75
+
})
76
+
});
77
+
```
78
+
79
+
Please note that the id should be unique for every entry in the collection.
80
+
The loader will also automatically convert the value into a slug to be easily used in URLs.
81
+
It's recommended to use e.g. the title of the entry to be easily searchable and readable.
82
+
**Do not use e.g. rich text fields as ids.**
83
+
65
84
## Type generation
66
85
67
86
The loader can automatically generate types for your collection.
@@ -116,6 +135,7 @@ This manual schema will **always override the automatic type generation**.
116
135
|`content`|`string \| Array<string>`|| The field in the collection to use as content. This can also be an array of fields. |
117
136
|`adminEmail`|`string`|| The email of the admin of the PocketBase instance. This is used for automatic type generation and access to private collections. |
118
137
|`adminPassword`|`string`|| The password of the admin of the PocketBase instance. This is used for automatic type generation and access to private collections. |
138
+
|`id`|`string`|| The field in the collection to use as unique id. Defaults to `id`. |
119
139
|`localSchema`|`string`|| The path to a local schema file. This is used for automatic type generation. |
120
140
|`jsonSchemas`|`Record<string, z.ZodSchema>`|| A record of Zod schemas to use for type generation of `json` fields. |
121
141
|`forceUpdate`|`boolean`|| If set to `true`, the loader will fetch every entry instead of only the ones modified since the last build. |
0 commit comments