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 9

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 62

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 306

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 327

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 416

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 360

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 371

Promise resolving to the deleted models

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 405

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 338

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 382

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 349

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 393

Promise resolving to the updated models

Promise.<Array.<M>>