pawcoding / astro-loader-pocketbase

A content loader for Astro that uses the PocketBase API
https://www.npmjs.com/package/astro-loader-pocketbase
MIT License
16 stars 2 forks source link

Handle views #4

Closed pawcoding closed 1 month ago

pawcoding commented 1 month ago

Requirements

Currently the loader assumes that the base fields of PocketBase are always present. However this is not the case for view collections. View collections only have:

The other two base fields created and updated are not necessarily present. So in case of a view these fields are optional and the loader cannot rely on them for build caching, sorting and in the type generation.

pawcoding commented 1 month ago

I've further investigated the issue and created and updated have a special behavior for view collections:

  1. You can leave them out in the SQL query so they will not be part of the view. This should probably result in the type Date | undefined for the fields.
  2. You can also alias another date column with updated (or created). This will return the other dates as updated, which is fine, since it's still a date. It can however break the incremental updates, since this functionality relies on the date being the timestamp of the last change to the entry, so I advice you to not do that.
  3. If you try to alias another column that does not have the type date to updated, the column will simply be ignored in the collection. On one hand this is strange, since it's not how a vanilla SQL database behaves. On the other hand this is prefect for our use case, since we can guaranty that the type will always be Date (or undefined).