Cockpit ORM
Create a representations of you collections and entries to manage data without manually fetching the Cockpit API.
npm install cockpit-orm# or yarn add cockpit-orm
Entry
The Entry class is for mapping one single entry of a collection.
- Create a new Entry class by extending
Entry
. - Use the schema given by Cockpit so your local entry knows the collection name and fields.
- Use a authenticated Cockpt SDK instance that will be called internally.
- Set an optional
slugField
to use a handy slug that will identify this Entry instead of_id
. When theslugField
is undefined the_id
field will be used.
;;; // Initiated CockpitSDK instance. static cockpit = cockpit; static slugField = "title_slug"; static schema = // Cockpit collection schema. name: "post" fields: name: "title" options: slug: true name: "body" ;
Sync new Post by slug.
async { const post = ; post; await post; // Fetches cockpit and fill all other fields. post; post;};
Add new entry.
const post = title: "Hello" ; post; // Hellopost; // false post; // POST to cockpit
Update entry.
async { const post = ; post; await post; // Fetches cockpit and fill all other fields. post; post; await post; // POST to cockpit};
Collection
The Collection
class is for fetching the whole collection entries.
;;; // Initiated CockpitSDK instance. static collectionName = "Posts"; static slugField = "title_slug"; static cockpit = cockpit;
Get entries
const posts = ; const entries = posts;
Custom methods
//... { return this; } const entries = ;