Overview
Entities module for managing app data. This module provides dynamic access to all entities in the app. Each entity gets a handler with full CRUD operations and additional utility methods. Entities are accessed dynamically using the pattern:base44.entities.EntityName.method()
This module is available to use with a client in all authentication modes:
- Anonymous or User authentication (
base44.entities): Access is scoped to the current user’s permissions. Anonymous users can only access public entities, while authenticated users can access entities they have permission to view or modify. - Service role authentication (
base44.asServiceRole.entities): Operations have elevated admin-level permissions. Can access all entities that the app’s admin role has access to.
Entity Handlers
An entity handler is the object you get when you access an entity throughbase44.entities.EntityName. Every entity in your app automatically gets a handler with CRUD methods for managing records.
For example, base44.entities.Task is an entity handler for Task records, and base44.entities.User is an entity handler for User records. Each handler provides methods like list(), create(), update(), and delete().
You don’t need to instantiate or import entity handlers. They’re automatically available for every entity you create in your app.
Built-in User Entity
Every app includes a built-inUser entity that stores user account information. This entity has special security rules that can’t be changed.
Regular users can only read and update their own user record. With service role authentication, you can read, update, and delete any user. You can’t create users using the entities module. Instead, use the functions of the auth module to invite or register new users.
Generated Types
If you’re working in a TypeScript project, you can generate types from your entity schemas to get autocomplete and type checking on all entity methods. See the Dynamic Types guide to get started.Examples
Entity Handler Methods
Entity handler providing CRUD operations for a specific entity type. Each entity in the app gets a handler with these methods for managing data.
list()
list<Lists records with optional pagination and sorting. Retrieves all records of this type with support for sorting, pagination, and field selection. Note: The maximum limit is 5,000 items per request.K extends keyof T>(
sort?,
limit?,
skip?,
fields?
):Promise<Pick<T,K>[]>
Parameters
Properties
Properties
A
SortField<T> specifying sort order, such as '-created_date' for descending. Defaults to '-created_date'.Maximum number of results to return. Defaults to
50.Number of results to skip for pagination. Defaults to
0.Array of field names to include in the response. Defaults to all fields.
Returns
Promise resolving to an array of records with selected fields.Examples
filter()
filter<Filters records based on a query. Retrieves records that match specific criteria with support for sorting, pagination, and field selection. Note: The maximum limit is 5,000 items per request.K extends keyof T>(
query,
sort?,
limit?,
skip?,
fields?
):Promise<Pick<T,K>[]>
Parameters
Properties
Properties
Query object with field-value pairs. Each key should be a field name
from your entity schema, and each value is the criteria to match. Records matching all
specified criteria are returned. Field names are case-sensitive.
A
SortField<T> specifying sort order, such as '-created_date' for descending. Defaults to '-created_date'.Maximum number of results to return. Defaults to
50.Number of results to skip for pagination. Defaults to
0.Array of field names to include in the response. Defaults to all fields.
Returns
Promise resolving to an array of filtered records with selected fields.Examples
get()
get(Gets a single record by ID. Retrieves a specific record using its unique identifier.id):Promise<T>
Parameters
The unique identifier of the record.
Returns
Promise<T>
Promise resolving to the record.
Example
create()
create(Creates a new record. Creates a new record with the provided data.data):Promise<T>
Parameters
Object containing the record data.
Returns
Promise<T>
Promise resolving to the created record.
Example
update()
update(Updates an existing record. Updates a record by ID with the provided data. Only the fields included in the data object will be updated.id,data):Promise<T>
Parameters
Properties
Properties
Returns
Promise<T>
Promise resolving to the updated record.
Examples
delete()
delete(Deletes a single record by ID. Permanently removes a record from the database.id):Promise<DeleteResult>
Parameters
The unique identifier of the record to delete.
Returns
DeleteResult
Result returned when deleting a single entity.
Properties
Properties
Whether the deletion was successful.
Example
deleteMany()
deleteMany(Deletes multiple records matching a query. Permanently removes all records that match the provided query.query):Promise<DeleteManyResult>
Parameters
Query object with field-value pairs. Each key should be a field name
from your entity schema, and each value is the criteria to match. Records matching all
specified criteria will be deleted. Field names are case-sensitive.
Returns
DeleteManyResult
Result returned when deleting multiple entities.
Properties
Properties
Example
bulkCreate()
bulkCreate(Creates multiple records in a single request. Efficiently creates multiple records at once. This is faster than creating them individually.data):Promise<T[]>
Parameters
Array of record data objects.
Returns
Promise<T[]>
Promise resolving to an array of created records.
Example
importEntities()
importEntities(Imports records from a file. Imports records from a file, typically CSV or similar format. The file format should match your entity structure. Requires a browser environment and can’t be used in the backend.file):Promise<ImportResult<T>>
Parameters
File object to import.
Returns
ImportResult<T>
Result returned when importing entities from a file.
Properties
Properties
Example
subscribe()
subscribe(Subscribes to realtime updates for all records of this entity type. Establishes a WebSocket connection to receive instant updates when any record is created, updated, or deleted. Returns an unsubscribe function to clean up the connection.callback): () =>void
Parameters
Callback function called when an entity changes. The callback receives an event object with the following properties:
type: The type of change that occurred -'create','update', or'delete'.data: The entity data after the change.id: The unique identifier of the affected entity.timestamp: ISO 8601 timestamp of when the event occurred.
Returns
Unsubscribe function to stop receiving updates.Example
Type Definitions
EntityRecord
EntityRecord = { [K in keyof EntityTypeRegistry]: EntityTypeRegistry[K] & ServerEntityFields }
Combines the EntityTypeRegistry schemas with server fields like id, created_date, and updated_date to give the complete record type for each entity. Use this when you need to type variables holding entity data.
Example
EntityTypeRegistry
Registry mapping entity names to their TypeScript types. The
types generate command fills this registry, then EntityRecord adds server fields.
SortField
SortField<Sort field type for entity queries. Accepts any field name from the entity type with an optional prefix:T> =keyof T|`+${keyof T}`|`-${keyof T}`
'+'prefix or no prefix: ascending sort'-'prefix: descending sort

