Refactor Query contract: uniform ergonomics for SQLite + PostgreSQL
- Add `publish_key()` default method to `Query` trait (returns `None`) - Add `mutation_exec!` macro for SQLite INSERT/UPDATE/DELETE ops; overrides `publish_key()` so the mutation carries its own invalidation key - Add `Store::exec()` which runs a mutation and auto-publishes its key — action handlers no longer need a separate `store.publish()` call - Add `PgQuery` trait + `pg_query_one!` / `pg_query_all!` macros (feature-gated on `pg_replication`) mirroring the SQLite Query API - Add `cx.run_pg(pool, query)` to `RenderContext` which executes a PgQuery and auto-subscribes its cache key — no more manual `cx.subscribe()` calls - Update todo example: replace plain mutation fns with `mutation_exec!` structs and `store.exec()` calls; remove `action_then_publish` helper - Update pg_replication example: add `ListMessages` via `pg_query_all!` and replace manual subscribe + raw query with `cx.run_pg()` https://claude.ai/code/session_01HXe8rAZPweU9j2piBo9MdG
This commit is contained in:
@@ -15,9 +15,18 @@ pub mod server;
|
||||
#[cfg(feature = "pg_replication")]
|
||||
pub mod pg_replication;
|
||||
|
||||
/// PostgreSQL query trait and macros (`pg_query_one!`, `pg_query_all!`).
|
||||
///
|
||||
/// Use `cx.run_pg(pool, query)` in render functions to execute a `PgQuery`
|
||||
/// and auto-subscribe to its cache key, exactly like `cx.run()` for SQLite.
|
||||
#[cfg(feature = "pg_replication")]
|
||||
pub mod pg_query;
|
||||
|
||||
pub use signal::{Signal, SignalStore, SignalOpts, mangle, client_only, global, data_signals};
|
||||
pub use query::{CacheKey, Query};
|
||||
pub use store::{Store, KVStore};
|
||||
#[cfg(feature = "pg_replication")]
|
||||
pub use pg_query::PgQuery;
|
||||
pub use context::{RenderContext, ComponentTree, ComponentNode};
|
||||
pub use connection::{ConnectionManager, ConnectionState, SubscriptionRegistry};
|
||||
pub use sse::{format_patch_elements, format_patch_signals};
|
||||
|
||||
Reference in New Issue
Block a user