Separate read and write addresses
Separate read and write addresses
A colon separates a datasource's read address from its write address. For example, a published HTTPS URL can serve readers while a storage URI receives refreshed data. This local recipe demonstrates the same behavior without cloud credentials.
Complete local setup, then download sales.csv, read-write.preql, and files.preql into one folder.
key sale_id int;
property sale_id.channel string;
property sale_id.amount float;
root datasource incoming (sale_id, channel, amount)
grain (sale_id)
query '''
select 4 as sale_id, 'store' as channel, 200.0 as amount
union all select 5, 'web', 90.0
''';
datasource snapshot (sale_id, channel, amount)
grain (sale_id)
file `./sales.csv` : `./sales-export.csv`;
# Write replacement data to the separate export address.
persist snapshot;
trilogy run read-write.preql duckdb
The snapshot datasource reads from sales.csv. When persist snapshot runs, Trilogy builds it from the alternative incoming source and writes to sales-export.csv. The resulting file contains:
sale_id,channel,amount
4,store,200.0
5,web,90.0
The original sales.csv still contains sales 1–3. Verify the original read address with:
trilogy run files.preql duckdb
It returns store revenue 170 and web revenue 80. Running the persist command again replaces the export with the same two rows.
The write address is not a fallback read path. Publishing or copying the exported file to the read address is a separate deployment step. Use matching file formats for both addresses; this recipe uses CSV for both. See file datasource syntax and persist statements.