docs/docs/en/flow-engine/flow-model-repository.md
FlowEngine provides a complete persistence system.
IFlowModelRepository is the model persistence interface for FlowEngine, defining operations such as remote loading, saving, and deleting of models. By implementing this interface, model data can be persisted to a backend database, API, or other storage media, enabling data synchronization between the frontend and backend.
findOne(query: Query): Promise<FlowModel | null>
Loads model data from a remote source based on the unique identifier uid.
save(model: FlowModel): Promise<any>
Saves the model data to remote storage.
destroy(uid: string): Promise<boolean>
Deletes the model from remote storage based on uid.
class FlowModelRepository implements IFlowModelRepository<FlowModel> {
constructor(private app: Application) {}
async findOne(query) {
const { uid, parentId } = query;
// Implementation: Get model by uid
return null;
}
async save(model: FlowModel) {
console.log('Saving model:', model);
// Implementation: Save model
return model;
}
async destroy(uid: string) {
// Implementation: Delete model by uid
return true;
}
}
flowEngine.setModelRepository(new FlowModelRepository(this.app));
await flowEngine.createModelAsync(options); // Create a local model instance
flowEngine.getModel(uid); // Get a local model instance
flowEngine.removeModel(uid); // Remove a local model instance
await flowEngine.loadModel(uid); // Load model from remote
await flowEngine.saveModel(model); // Save model to remote
await flowEngine.destroyModel(uid); // Delete model from remote
const model = await this.flowEngine.createModelAsync({
use: 'FlowModel',
});
await model.save(); // Save to remote
await model.destroy(); // Delete from remote