FlashcoreModel<T>
Class: FlashcoreModel<T>
FlashcoreModel class.
Provides CRUD operations for a model defined by a schema.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends { id: string; } | { id: string; } |
Constructors
new FlashcoreModel()
new FlashcoreModel<T>(
name,
schemaFields,
adapter,
options?): FlashcoreModel<T>Parameters
| Parameter | Type |
|---|---|
name | string |
schemaFields | SchemaFields |
adapter | FlashcoreAdapter<string, unknown> |
options? | FlashcoreModelOptions |
Returns
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
hooks? | readonly | ModelHooks<T> | undefined | - |
meta | readonly | Record<string, unknown> | {} | Plugin metadata storage. |
name | readonly | string | undefined | - |
namespace? | readonly | string | undefined | - |
schema | readonly | NormalizedSchema | undefined | - |
Methods
count()
count(args?): Promise<number>Get the record count, optionally with filtering.
Parameters
| Parameter | Type | Description |
|---|---|---|
args? | CountArgs<T> | Optional count arguments with where clause |
Returns
Promise<number>
Count of matching records
create()
create(data): Promise<T>Create a new record.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | CreateInput<T> | Record data (id is auto-generated if not provided) |
Returns
Promise<T>
Created record
createMany()
createMany(args): Promise<CreateManyResult<T>>Create multiple records atomically. Requires adapter with ACID support (transaction or atomicBatch).
Parameters
| Parameter | Type | Description |
|---|---|---|
args | CreateManyArgs<T> | Create many arguments with data array |
Returns
Promise<CreateManyResult<T>>
Created records array
delete()
delete(args): Promise<T>Delete a record.
Parameters
| Parameter | Type | Description |
|---|---|---|
args | DeleteArgs<T> | Delete arguments with where clause |
Returns
Promise<T>
Deleted record or null if not found
deleteMany()
deleteMany(args): Promise<BatchResult>Delete multiple records atomically. Requires adapter with ACID support (transaction or atomicBatch).
Parameters
| Parameter | Type | Description |
|---|---|---|
args | DeleteManyArgs<T> | Delete many arguments with where clause |
Returns
Promise<BatchResult>
Batch result with count of deleted records
findFirst()
findFirst(args?): Promise<T>Find the first matching record.
Parameters
| Parameter | Type | Description |
|---|---|---|
args? | FindFirstArgs<T> | FindFirst arguments |
Returns
Promise<T>
First matching record or null
findMany()
findMany(args?): Promise<T[]>Find multiple records with filtering, ordering, and pagination.
Parameters
| Parameter | Type | Description |
|---|---|---|
args? | FindManyArgs<T> | FindMany arguments |
Returns
Promise<T[]>
Array of matching records
findManyStream()
findManyStream(args?): AsyncGenerator<T, void, undefined>Stream records for memory-efficient processing.
Parameters
| Parameter | Type | Description |
|---|---|---|
args? | FindManyArgs<T> | FindMany arguments |
Returns
AsyncGenerator<T, void, undefined>
Yields
Records one by one
findUnique()
findUnique(args): Promise<T>Find a unique record by ID or unique field.
Parameters
| Parameter | Type | Description |
|---|---|---|
args | FindUniqueArgs<T> | Find arguments with where clause |
Returns
Promise<T>
Found record or null
getIndexedFields()
getIndexedFields(): string[]Get indexed field names.
Returns
string[]
getRelations()
getRelations(): RelationDef[]Get relation definitions.
Returns
getSchema()
getSchema(): Map<string, {
indexed: boolean;
name: string;
optional: boolean;
primaryKey: boolean;
type: string;
unique: boolean;
}>Get the raw schema fields.
Returns
Map<string, {
indexed: boolean;
name: string;
optional: boolean;
primaryKey: boolean;
type: string;
unique: boolean;
}>
getSchemaChecksum()
getSchemaChecksum(): stringGet the schema checksum.
Returns
string
getUniqueFields()
getUniqueFields(): string[]Get unique field names.
Returns
string[]
pluginContext()
pluginContext(pluginName): PluginContextGet plugin context by name.
Used by plugins to access their state and methods from model operations.
Parameters
| Parameter | Type | Description |
|---|---|---|
pluginName | string | Name of the plugin |
Returns
Plugin context
Throws
Error if plugin not found
update()
update(args): Promise<T>Update a record.
Parameters
| Parameter | Type | Description |
|---|---|---|
args | UpdateArgs<T> | Update arguments with where and data |
Returns
Promise<T>
Updated record or null if not found
updateMany()
updateMany(args): Promise<BatchResult>Update multiple records atomically. Requires adapter with ACID support (transaction or atomicBatch).
Parameters
| Parameter | Type | Description |
|---|---|---|
args | UpdateManyArgs<T> | Update many arguments with where clause and data |
Returns
Promise<BatchResult>
Batch result with count of updated records
upsert()
upsert(args): Promise<T>Create or update a record based on unique identifier.
Parameters
| Parameter | Type | Description |
|---|---|---|
args | UpsertArgs<T> | Upsert arguments with where, create, and update data |
Returns
Promise<T>
Created or updated record
