Class

FabricCrudContract

FabricCrudContract()

Constructor

# new FabricCrudContract()

Provides standard create, read, update, and delete operations for models in Fabric chaincode

Base contract class for CRUD operations in Fabric chaincode

sequenceDiagram participant Client participant Contract participant Repository participant Adapter participant StateDB Client->>Contract: create(ctx, model) Contract->>Repository: repository(ctx) Contract->>Repository: create(model, ctx) Repository->>Adapter: create(tableName, id, record, transient, ctx) Adapter->>StateDB: putState(id, serializedData) StateDB-->>Adapter: Success Adapter-->>Repository: record Repository-->>Contract: model Contract-->>Client: model

View Source contracts/crud/crud-contract.ts, line 11

Example
```typescript
// Define a model

Extends

  • Contract

Classes

FabricCrudContract

Initializes a contract with a name and model class

FabricCrudContract

Initializes a contract with a name and model class

Members

# adapter

Shared adapter instance for all contract instances

.

Shared adapter instance for all contract instances

View Source contracts/crud/crud-contract.ts, line 64

FabricContractAdapter

# protected static adapter

Shared adapter instance for all contract instances

.

Shared adapter instance for all contract instances

View Source contracts/crud/crud-contract.ts, line 316

Methods

# async create(ctx, model, …args) → {Promise.<M>}

Delegates to the repository's create method

Creates a single model in the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

model M

The model to create

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 337

Promise resolving to the created model

Promise.<M>

# async createAll(ctx, models, …args) → {Promise.<Array.<M>>}

Delegates to the repository's createAll method

Creates multiple models in the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

models Array.<M>

The models to create

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 439

Promise resolving to the created models

Promise.<Array.<M>>

# async delete(ctx, key, …args) → {Promise.<M>}

Delegates to the repository's delete method

Deletes a single model from the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

key string | number

The key of the model to delete

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 370

Promise resolving to the deleted model

Promise.<M>

# async deleteAll(keys, ctx, …args) → {Promise.<Array.<M>>}

Delegates to the repository's deleteAll method

Deletes multiple models from the state database

Parameters:
Name Type Attributes Description
keys Array.<string> | Array.<number>

The keys of the models to delete

ctx Ctx

The Fabric chaincode context

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 381

Promise resolving to the deleted models

Promise.<Array.<M>>

# async query(condition, orderBy, orderopt, limitopt, skipopt) → {Promise.<Array.<M>>}

Provides a simplified way to query the database with common query parameters.

Executes a query with the specified conditions and options.

Parameters:
Name Type Attributes Default Description
condition Condition.<M>

The condition to filter records.

orderBy

The field to order results by.

order OrderDirection <optional>
OrderDirection.ASC

The sort direction.

limit number <optional>

Optional maximum number of results to return.

skip number <optional>

Optional number of results to skip.

View Source contracts/crud/crud-contract.ts, line 416

The query results as model instances.

Promise.<Array.<M>>

# async raw(ctx, rawInput, docsOnly, …args) → {Promise.<any>}

Delegates to the repository's raw method

Executes a raw query against the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

rawInput any

The query to execute

docsOnly boolean

Whether to return only documents

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 428

Promise resolving to the query results

Promise.<any>

# async read(ctx, key, …args) → {Promise.<M>}

Delegates to the repository's read method

Reads a single model from the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

key string | number

The key of the model to read

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 348

Promise resolving to the retrieved model

Promise.<M>

# async readAll(ctx, keys, …args) → {Promise.<Array.<M>>}

Delegates to the repository's readAll method

Reads multiple models from the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

keys Array.<string> | Array.<number>

The keys of the models to read

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 392

Promise resolving to the retrieved models

Promise.<Array.<M>>

# async update(ctx, model, …args) → {Promise.<M>}

Delegates to the repository's update method

Updates a single model in the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

model M

The model to update

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 359

Promise resolving to the updated model

Promise.<M>

# async updateAll(ctx, models, …args) → {Promise.<Array.<M>>}

Delegates to the repository's updateAll method

Updates multiple models in the state database

Parameters:
Name Type Attributes Description
ctx Ctx

The Fabric chaincode context

models Array.<M>

The models to update

args Array.<any> <repeatable>

Additional arguments

View Source contracts/crud/crud-contract.ts, line 403

Promise resolving to the updated models

Promise.<Array.<M>>