0.1.0 • Published 1 year ago
@ng-pocketbase/core v0.1.0
@ng-pocketbase/core
This library provides a set of components and services for the usage with Pocketbase. It heavily uses pocketbase's realtime api, so any changes made to the database will be reflected in the app instantly without polling.
Installation
yarn add @ng-pocketbase/core
or npm install @ng-pocketbase/core
Documentation
See GitHub.
Examples
@Injectable({providedIn: "root"})
export class DetailsService extends BasicCrud<Detail> {
constructor(pbs: PocketBaseService) {
super(pbs, "details");
this.requestRecords();
}
protected createItem(record: Record): Detail {
return {
id: record.id,
feed: record.feed,
weight: parseInt(record.weight),
name: record.name,
};
}
}
Now you can use it like so
export class DetailsComponent implements OnInit {
constructor(private DetailsService: DetailsService) {
}
public ngOnInit(): void {
this.DetailsService.getItems().subscribe((value: Array<Detail>) => {
this.details = value;
});
this.DetailsService.create({...}).subscribe((value: Detail) => { console.log(value.id); // fdsafdsadadfs });
this.DetailsService.getById("fdsafdsadadfs").subscribe((value: Detail) => { });
this.DetailsService.update("fdsafdsadadfs", {name: "test"}).subscribe((value: Detail) => { });
this.DetailsService.delete("fdsafdsadadfs").subscribe((success: boolean) => { });
}
}
Changelog
- 0.0.5
- fix: only adding realtime records if they are not already loaded
- feature: auth interceptor
- feature: differential of admins and normal users
License
Mozilla Public License Version 2.0