# Config 5: Simple & Practical Config ## Scenario **Real-world practical scenario** dengan configuration yang umum digunakan: database connection, cache settings, dengan **simple nested objects** dan **arrays of objects**. ## Use Case Standard application configuration untuk database connection pooling dan cache cluster configuration. --- ## Input: CONFIG5.yaml ```yaml database: host: localhost port: 5432 name: middleware_db username: ace_user password: secure_pass_123 connectionPool: minSize: 5 maxSize: 20 timeout: 30 allowedIPs: - 192.168.1.100 - 192.168.1.101 - 10.0.0.50 cache: enabled: true ttl: 3600 provider: redis nodes: - host: redis1.example.com port: 6379 - host: redis2.example.com port: 6379 ``` --- ## Output: hasilParseConfig5.json ```json { "database": { "host": "localhost", "port": "5432", "name": "middleware_db", "username": "ace_user", "password": "secure_pass_123", "connectionPool": { "minSize": "5", "maxSize": "20", "timeout": "30" }, "allowedIPs": ["192.168.1.100", "192.168.1.101", "10.0.0.50"] }, "cache": { "enabled": "true", "ttl": "3600", "provider": "redis", "nodes": [ { "host": "redis1.example.com", "port": "6379" }, { "host": "redis2.example.com", "port": "6379" } ] } } ``` --- ## ESQL Usage ### Get Database Config ```esql DECLARE dbConfig REFERENCE TO Environment.Variables; DECLARE success BOOLEAN; CALL ACE_LIB.getConfig( 'APP_DB_CONFIG', 'database', '/path/to/CONFIG5.yaml', '600', dbConfig ) INTO success; IF success THEN -- Connection details DECLARE dbHost CHARACTER dbConfig.host; DECLARE dbPort CHARACTER dbConfig.port; DECLARE dbName CHARACTER dbConfig.name; -- Connection pool settings DECLARE minPool CHARACTER dbConfig.connectionPool.minSize; DECLARE maxPool CHARACTER dbConfig.connectionPool.maxSize; -- Allowed IPs DECLARE ipRef REFERENCE TO dbConfig.allowedIPs[1]; WHILE LASTMOVE(ipRef) DO DECLARE allowedIP CHARACTER ipRef; -- "192.168.1.100", "192.168.1.101", "10.0.0.50" MOVE ipRef NEXTSIBLING; END WHILE; END IF; ``` ### Get Cache Config ```esql DECLARE cacheConfig REFERENCE TO Environment.Variables; DECLARE success BOOLEAN; CALL ACE_LIB.getConfig( 'APP_CACHE_CONFIG', 'cache', '/path/to/CONFIG5.yaml', '600', cacheConfig ) INTO success; IF success THEN -- Cache settings DECLARE cacheEnabled CHARACTER cacheConfig.enabled; DECLARE cacheTTL CHARACTER cacheConfig.ttl; DECLARE cacheProvider CHARACTER cacheConfig.provider; -- Redis nodes DECLARE nodeRef REFERENCE TO cacheConfig.nodes[1]; WHILE LASTMOVE(nodeRef) DO DECLARE nodeHost CHARACTER nodeRef.host; DECLARE nodePort CHARACTER nodeRef.port; -- Connect to redis node... MOVE nodeRef NEXTSIBLING; END WHILE; END IF; ``` --- ## Key Features Tested ✅ Multiple root keys (`database`, `cache`) ✅ Simple nested objects (1-level deep) ✅ Arrays of simple strings (`allowedIPs`) ✅ Arrays of objects (`nodes`) ✅ Practical real-world config structure ✅ Multiple configs dari same file --- ## Important Notes - Config ini representasi typical application configuration - Dapat load multiple keys dari same file dengan cache ID berbeda - Structure simple tapi complete untuk production use - Numeric dan boolean values jadi string (`"5432"`, `"true"`) --- [⬅️ Back to README](../README.md)