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:
Entity specific initialization (recommended)
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'
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
id | string | yes | The 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
}
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
payload | object | yes | The 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 }
]
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
payload | array | yes | Array 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
}
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
payload | object | yes | The 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 }
]
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
payload | array | yes | Array of entity objects to update. Each object must include all primary keys |
search
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
}
}
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
payload | BshSearch | yes | The 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'
}
]
}
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
payload | object | yes | The 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'
}
]
}
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
payload | BshSearch | yes | The search criteria to identify records to delete. See BSH Search documentation |
deleteById
await entitiesService.deleteById({
entity: 'Products',
id: 'product-1'
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
id | string | yes | The 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'
}
]
}
});| Property | Type | Required | Description |
|---|---|---|---|
entity | string | yes, if not provided in initialization | The entity name. If not provided, uses the entity from constructor |
format | csv,json,excel | yes | The export file format |
filename | string | no | The filename for the export. If not provided, uses a default name with timestamp |
payload | BshSearch | yes | The 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'
}
});