Data Preparation Examples
This directory contains examples demonstrating how to separate data preparation from script evaluation in go-polyscript.
Overview
The data preparation pattern separates static data from runtime data, making code more modular and flexible. This pattern uses a composite data provider combining static and dynamic data sources, with a clear separation between configuration, preparation, and evaluation phases.
When to Use This Pattern
This pattern is valuable for:
- Distributed Architecture: Prepare data on one system (e.g., web server) and evaluate on another (e.g., worker)
- Separation of Concerns: Clearly separate data processing from script execution
- Layered Data Access: Combine static data with runtime data
- Performance Optimization: Prepare data asynchronously while other operations are happening
Implementation Pattern
These examples follow a consistent three-phase pattern:
- Create evaluator with static data: Set up an evaluator with configuration data that remains constant across executions
- Prepare runtime data: Add dynamic data to the context using the
AddDataToContext
method
- Evaluate script: Execute the script with the enriched context
Running the Examples
Each example follows the same pattern but demonstrates it with a different script engine:
go run examples/data-prep/<engine>/main.go
Note: The Extism example requires a WASM file. If not found automatically, you may need to compile it using the Makefile
in /engines/extism/wasmdata/
.