WASM Procedures: API Reference
WASM Procedures: API Reference
Documentation Home > User Guides > Features > API Reference
Overview
Complete API reference for HeliosDB WASM Procedures, including SQL statements, host functions, and error codes.
Related Sections:
- Host Functions - Detailed host function documentation
- Procedure Management - Managing procedures
- Language SDKs - SDK-specific APIs
API Reference
SQL Statements
CREATE PROCEDURE
CREATE [OR REPLACE] PROCEDURE name (params)[RETURNS type]LANGUAGE wasm[SECURITY PROFILE 'profile'][WITH (options)]AS source;Options:
precompile: boolean - Precompile modulecompilation_tier: ‘interpreter’ | ‘baseline’ | ‘optimizing’fuel_metering: boolean - Enable fuel meteringfuel_limit: integer - Fuel limitprofiling: boolean - Enable profilingdebug_mode: boolean - Enable debug mode
ALTER PROCEDURE
ALTER PROCEDURE name SET SOURCE '/path/to/new.wasm' | SET SECURITY PROFILE 'profile' | SET log_level = 'level' | SET option = value;DROP PROCEDURE
DROP PROCEDURE [IF EXISTS] name [CASCADE];CALL
CALL procedure_name(args);SELECT procedure_name(args);Host Function Reference
Database:
exec_sql(sql: string) -> ResultSetexec_prepared(stmt_id: i64) -> ResultSetprepare_statement(sql: string) -> i64begin_transaction() -> Transactioncommit_transaction(tx: Transaction) -> Result<()>rollback_transaction(tx: Transaction) -> Result<()>
Key-Value:
kv_get(key: bytes) -> Option<bytes>kv_set(key: bytes, value: bytes) -> Result<()>kv_delete(key: bytes) -> Result<()>
Document:
doc_get(collection: string, id: string) -> Option<JSON>doc_insert(collection: string, doc: JSON) -> stringdoc_update(collection: string, id: string, doc: JSON) -> Result<()>doc_delete(collection: string, id: string) -> Result<()>
Graph:
graph_query(query: string) -> GraphResultgraph_shortest_path(from: NodeId, to: NodeId) -> Path
Vector:
vector_search(collection: string, vector: Vec<f32>, top_k: i32) -> Vec<Match>vector_insert(collection: string, vector: Vec<f32>, metadata: JSON) -> string
HTTP:
http_get(url: string) -> HTTPResponsehttp_post(url: string, body: bytes, headers: Map) -> HTTPResponsehttp_put(url: string, body: bytes, headers: Map) -> HTTPResponsehttp_delete(url: string) -> HTTPResponse
Logging:
log_trace(message: string)log_debug(message: string)log_info(message: string)log_warn(message: string)log_error(message: string)
Metrics:
metric_increment(name: string, value: i64)metric_gauge(name: string, value: f64)metric_histogram(name: string, value: f64)
Crypto:
sha256(data: bytes) -> bytessha512(data: bytes) -> bytesblake3(data: bytes) -> bytesrandom_bytes(count: i32) -> bytes
Time:
current_timestamp() -> i64format_timestamp(timestamp: i64, format: string) -> string
Security:
request_capability(cap: Capability) -> Result<()>check_capability(cap: Capability) -> bool
Error Codes
| Code | Name | Description |
|---|---|---|
| 01000 | WASM_COMPILATION_ERROR | Failed to compile WASM module |
| 01001 | WASM_INSTANTIATION_ERROR | Failed to instantiate module |
| 01002 | WASM_EXECUTION_ERROR | Procedure execution failed |
| 01003 | WASM_TIMEOUT | Execution exceeded time limit |
| 01004 | WASM_MEMORY_EXCEEDED | Memory limit exceeded |
| 01005 | WASM_FUEL_EXHAUSTED | Fuel limit exhausted |
| 01006 | WASM_SECURITY_VIOLATION | Security capability violation |
| 01007 | WASM_PERMISSION_DENIED | Permission denied |
| 01008 | WASM_INVALID_PARAMETER | Invalid parameter |
| 01009 | WASM_MODULE_NOT_FOUND | Procedure not found |
System Catalogs
heliosdb_procedures
Information about all procedures:
SELECT * FROM heliosdb_procedures;Columns:
name: Procedure namelanguage: ‘wasm’security_profile: Security profile namesize_bytes: WASM module sizecreated_at: Creation timestamplast_modified: Last modification timestampversion: Current version
heliosdb_procedure_metrics
Performance metrics:
SELECT * FROM heliosdb_procedure_metrics;Columns:
procedure_name: Procedure nametotal_calls: Total number of callssuccessful_calls: Successful executionsfailed_calls: Failed executionssuccess_rate: Success rate percentageavg_execution_time_ms: Average execution timemin_execution_time_ms: Minimum execution timemax_execution_time_ms: Maximum execution timep50_execution_time_ms: 50th percentilep95_execution_time_ms: 95th percentilep99_execution_time_ms: 99th percentile
heliosdb_procedure_errors
Error tracking:
SELECT * FROM heliosdb_procedure_errors;Columns:
procedure_name: Procedure nameerror_message: Error messageerror_count: Number of occurrenceslast_occurrence: Last occurrence timestampstack_trace: Stack trace (if available)source_location: Source code location
heliosdb_procedure_logs
Procedure logs:
SELECT * FROM heliosdb_procedure_logs;Columns:
timestamp: Log timestampprocedure_name: Procedure namelog_level: Log level (trace, debug, info, warn, error)message: Log messageexecution_id: Execution identifier
heliosdb_wasm_cache_stats
Module cache statistics:
SELECT * FROM heliosdb_wasm_cache_stats;Columns:
cached_modules: Number of cached modulescache_hits: Cache hitscache_misses: Cache misseshit_rate: Hit rate percentageevictions: Number of evictions
heliosdb_wasm_pool_stats
Instance pool statistics:
SELECT * FROM heliosdb_wasm_pool_stats;Columns:
procedure_name: Procedure namepool_size: Configured pool sizeavailable_instances: Available instancesin_use_instances: Instances in usetotal_acquisitions: Total acquisitionsavg_acquisition_time_ms: Average acquisition time
Configuration Parameters
Global Settings
-- Cache configurationSET heliosdb.wasm_module_cache_size = 1000;SET heliosdb.wasm_module_cache_ttl = 3600;SET heliosdb.wasm_module_cache_enabled = true;
-- Pool configurationSET heliosdb.wasm_instance_pool_size = 10;SET heliosdb.wasm_instance_max_age_seconds = 300;SET heliosdb.wasm_instance_max_executions = 1000;
-- Memory configurationSET heliosdb.wasm_memory_pool_size_mb = 1024;SET heliosdb.wasm_memory_pooling_enabled = true;
-- Logging configurationSET heliosdb.procedure_log_level = 'info';SET heliosdb.procedure_log_retention_days = 30;
-- Execution limitsSET heliosdb.wasm_default_fuel_limit = 1000000000;SET heliosdb.wasm_default_memory_limit_mb = 512;SET heliosdb.wasm_default_timeout_ms = 30000;Procedure-Specific Settings
ALTER PROCEDURE my_procedure SET fuel_limit = 10000000000 SET fuel_metering = false SET compilation_tier = 'optimizing' SET profiling = true SET debug_mode = false SET log_level = 'info';Key Takeaways
- Complete SQL API: Full DDL support for procedure management
- Rich Host Functions: 40+ host functions across 8 categories
- System Catalogs: Comprehensive metadata and metrics
- Error Codes: Standardized error codes for diagnostics
- Configuration: Flexible global and per-procedure settings
Quick Reference
Create Procedure:
CREATE PROCEDURE name(params) RETURNS type LANGUAGE wasm AS source;Call Procedure:
SELECT procedure_name(args);View Metrics:
SELECT * FROM heliosdb_procedure_metrics WHERE procedure_name = 'name';View Errors:
SELECT * FROM heliosdb_procedure_errors WHERE procedure_name = 'name';Next Steps
- Host Functions - Detailed host function documentation
- Language SDKs - SDK-specific APIs
- Conclusion - Summary and resources
Navigation: ← Migration Guide | Index | Conclusion →