Skip to content

Commit 5793c99

Browse files
committed
added collections.truncate method
1 parent 375d6ba commit 5793c99

19 files changed

+88
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
- Added new `pb.collections.getScaffolds()` method to retrieve a type indexed map with the collection models (base, auth, view) loaded with their defaults.
6363

64+
- Added new `pb.collections.truncate(idOrName)` to delete all records associated with the specified collection.
65+
6466
- Added the submitted fetch options as 3rd last argument in the `pb.afterSend` hook.
6567

6668
- ⚠️ Admins are converted to `_superusers` auth collection and there is no longer `AdminService` and `AdminModel` types.

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -936,17 +936,20 @@ const result = await batch.send()
936936
// Returns the first found collection matching the specified filter.
937937
🔐 pb.collections.getFirstListItem(filter, options = {});
938938

939-
// Returns a single collection by its id.
940-
🔐 pb.collections.getOne(id, options = {});
939+
// Returns a single collection by its id or name.
940+
🔐 pb.collections.getOne(idOrName, options = {});
941941

942942
// Creates (aka. register) a new collection.
943943
🔐 pb.collections.create(bodyParams = {}, options = {});
944944

945-
// Updates an existing collection by its id.
946-
🔐 pb.collections.update(id, bodyParams = {}, options = {});
945+
// Updates an existing collection by its id or name.
946+
🔐 pb.collections.update(idOrName, bodyParams = {}, options = {});
947947

948-
// Deletes a single collection by its id.
949-
🔐 pb.collections.delete(id, options = {});
948+
// Deletes a single collection by its id or name.
949+
🔐 pb.collections.delete(idOrName, options = {});
950+
951+
// Deletes all records associated with the specified collection.
952+
🔐 pb.collections.truncate(idOrName, options = {});
950953

951954
// Imports the provided collections.
952955
🔐 pb.collections.import(collections, deleteMissing = false, options = {});

dist/pocketbase.cjs.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,12 @@ declare class CollectionService extends CrudService<CollectionModel> {
938938
getScaffolds(options?: CommonOptions): Promise<{
939939
[key: string]: CollectionModel;
940940
}>;
941+
/**
942+
* Deletes all records associated with the specified collection.
943+
*
944+
* @throws {ClientResponseError}
945+
*/
946+
truncate(collectionIdOrName: string, options?: CommonOptions): Promise<true>;
941947
}
942948
interface HourlyStats {
943949
total: number;

dist/pocketbase.cjs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.d.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,12 @@ declare class CollectionService extends CrudService<CollectionModel> {
981981
getScaffolds(options?: CommonOptions): Promise<{
982982
[key: string]: CollectionModel;
983983
}>;
984+
/**
985+
* Deletes all records associated with the specified collection.
986+
*
987+
* @throws {ClientResponseError}
988+
*/
989+
truncate(collectionIdOrName: string, options?: CommonOptions): Promise<true>;
984990
}
985991
interface HourlyStats {
986992
total: number;

dist/pocketbase.es.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,12 @@ declare class CollectionService extends CrudService<CollectionModel> {
981981
getScaffolds(options?: CommonOptions): Promise<{
982982
[key: string]: CollectionModel;
983983
}>;
984+
/**
985+
* Deletes all records associated with the specified collection.
986+
*
987+
* @throws {ClientResponseError}
988+
*/
989+
truncate(collectionIdOrName: string, options?: CommonOptions): Promise<true>;
984990
}
985991
interface HourlyStats {
986992
total: number;

dist/pocketbase.es.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)