1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Bevy integration for [SpacetimeDB](https://spacetimedb.com).
//!
//! `bevy_stdb` adapts SpacetimeDB's connection and callback model into
//! Bevy-style resources, systems, and read-only message readers. Everything is
//! configured through [`StdbPlugin`](crate::prelude::StdbPlugin).
//!
//! # Architecture
//!
//! The crate is organized around four lifecycle concerns:
//!
//! - **Connection** — Manage the connection lifecycle on demand via
//! [`StdbCommands`](crate::prelude::StdbCommands), and expose the active
//! connection as [`StdbConnection`](crate::prelude::StdbConnection).
//! - **Tables** — Register internal channels for Bevy
//! [`Message`](bevy_ecs::prelude::Message) values once at startup and
//! re-bind SDK table callbacks whenever a connection becomes active. Row
//! changes are consumed through read-only reader aliases such as
//! [`ReadInsertMessage`](crate::prelude::ReadInsertMessage),
//! [`ReadDeleteMessage`](crate::prelude::ReadDeleteMessage),
//! [`ReadUpdateMessage`](crate::prelude::ReadUpdateMessage), and
//! [`ReadInsertUpdateMessage`](crate::prelude::ReadInsertUpdateMessage).
//! - **Subscriptions** — Store subscription intent separately from the live
//! connection via [`StdbSubscriptions`](crate::prelude::StdbSubscriptions)
//! so queries are automatically re-applied after reconnects.
//! - **Reconnect** — Optionally retry failed connections with configurable
//! backoff via [`StdbReconnectOptions`](crate::prelude::StdbReconnectOptions).
//!
//! # Quick start
//!
//! ```ignore
//! use bevy::prelude::*;
//! use bevy_stdb::prelude::*;
//! // Generated by `spacetime generate`:
//! use module_bindings::{DbConnection, RemoteModule, PlayerRow};
//!
//! #[derive(Clone, Eq, PartialEq, Hash)]
//! enum SubKey { Players }
//!
//! fn main() {
//! App::new()
//! .add_plugins(DefaultPlugins)
//! .add_plugins(
//! StdbPlugin::<DbConnection, RemoteModule>::default()
//! .with_database_name("my_module")
//! .with_uri("http://localhost:3000")
//! .with_background_driver(DbConnection::run_threaded)
//! .with_reconnect(StdbReconnectOptions::default())
//! .with_subscriptions::<SubKey>()
//! .add_table::<PlayerRow>(|reg, db| reg.bind(db.player()))
//! )
//! .add_systems(Update, (on_player_insert, subscribe_players_on_connect))
//! .run();
//! }
//!
//! fn subscribe_players_on_connect(
//! mut connected: ReadStdbConnectedMessage,
//! mut subs: ResMut<StdbSubscriptions<SubKey, RemoteModule>>,
//! ) {
//! if connected.read().next().is_some() {
//! subs.subscribe_sql(SubKey::Players, "SELECT * FROM player");
//! }
//! }
//!
//! fn on_player_insert(mut msgs: ReadInsertMessage<PlayerRow>) {
//! for msg in msgs.read() {
//! info!("player inserted: {:?}", msg.row);
//! }
//! }
//! ```
//!
//! See the [`StdbPlugin`](crate::prelude::StdbPlugin) docs for the full
//! builder API and the [README](https://github.com/onx2/bevy_stdb)
//! for detailed guides on connection driving, table registration,
//! subscriptions, and delayed connections.
compile_error!;
/// Common imports for `bevy_stdb`.