Skip to Content
🎉 New release with new features and improvements! V0.0.2 Release →

Entities Service

The Entities Service provides comprehensive CRUD operations for entity management. It supports create, update, search, delete, export operations. The entity name can be specified in the service initialization or passed as a parameter to each method.

Initialization

You can initialize the entities service in two ways:

this allows to user to use the entities service without passing the entity name to each method.

const bshEngine = new BshEngine({ host: 'https://your-instance.com' }); const productsService = bshEngine.entity('Products');

Methods

findById

await entitiesService.findById({ entity: 'Products', id: 'product-1' });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
idstringyesThe ID of the entity record to retrieve

create

await entitiesService.create({ entity: 'Products', payload: { id: 'product-1', name: 'Product 1', description: 'Product 1 description', price: 100 } });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
payloadobjectyesThe entity data to create. Fields depend on the entity schema

createMany

await entitiesService.createMany({ entity: 'Products', payload: [ { id: 'product-1', name: 'Product 1', description: 'Product 1 description', price: 100 }, { id: 'product-2', name: 'Product 2', description: 'Product 2 description', price: 200 } ] });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
payloadarrayyesArray of entity objects to create. Each object should match the entity schema

update

await entitiesService.update({ entity: 'Products', payload: { id: 'product-1', name: 'Updated Product 1', description: 'Updated Product 1 description', price: 100 } });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
payloadobjectyesThe entity data to update. Must include all primary keys

updateMany

await entitiesService.updateMany({ entity: 'Products', payload: [ { id: 'product-1', name: 'Updated Product 1', description: 'Updated Product 1 description', price: 100 }, { id: 'product-2', name: 'Updated Product 2', description: 'Updated Product 2 description', price: 200 } ] });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
payloadarrayyesArray of entity objects to update. Each object must include all primary keys
await entitiesService.search({ entity: 'Products', payload: { fields: ['id', 'name', 'description', 'price'], filters: [ { field: 'name', operator: 'ilike', value: 'Product 1' } ], sort: [ { field: 'name', direction: 1 } ], pagination: { page: 0, size: 10 } } });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
payloadBshSearchyesThe search criteria. See BSH Search documentation for details

count

// Count all entities await entitiesService.count({ entity: 'Products' }); // Count filtered entities await entitiesService.count({ entity: 'Products', payload: { filters: [ { field: 'name', operator: 'eq', value: 'ApiKey 1' } ] } });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
payloadobjectyesThe search criteria to count the entities. See BSH Search documentation

delete

await entitiesService.delete({ entity: 'Products', payload: { filters: [ { field: 'name', operator: 'eq', value: 'Product 1' } ] } });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
payloadBshSearchyesThe search criteria to identify records to delete. See BSH Search documentation

deleteById

await entitiesService.deleteById({ entity: 'Products', id: 'product-1' });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
idstringyesThe ID of the entity record to delete

export

await entitiesService.export({ entity: 'Products', format: 'csv', filename: 'products_export', payload: { filters: [ { field: 'name', operator: 'eq', value: 'Product 1' } ] } });
PropertyTypeRequiredDescription
entitystringyes, if not provided in initializationThe entity name. If not provided, uses the entity from constructor
formatcsv,json,excelyesThe export file format
filenamestringnoThe filename for the export. If not provided, uses a default name with timestamp
payloadBshSearchyesThe search criteria to determine which records to export. See BSH Search documentation

Core Entities

The BshEngine exposes core entities that are part of the core system, you can access them using the bshEngine.entities.core.<entityName> service.

Entity
BshEntities
BshSchemas
BshTypes
BshUsers
BshPolicies
BshRoles
BshFiles
BshConfigurations
BshEmails
BshEmailTemplates
BshEventLogs
BshTriggers
BshTriggerInstances
await bshEngine.entities.core.BshEntities.findById({ id: 'Entity-Id' });
await bshEngine.entities.core.BshRoles.create({ payload: { name: 'Role Name', description: 'Role Description' } });