A simple chat application built with SpacetimeDB.
QuickStart Chat is a basic chat application that demonstrates the core functionality of SpacetimeDB. It allows users to:
- Connect to a chat room
- Set their username
- Send messages to the chat room
- See who is online
The application uses SpacetimeDB's real-time database capabilities to synchronize data across all connected clients.
quickstart-chat/
├── server/ # Server-side code
│ ├── src/
│ │ └── lib.rs # Main module code with tables and reducers
│ ├── Cargo.toml # Rust dependencies
│ └── .cargo/
│ └── config.toml # Cargo configuration for WebAssembly
└── README.md # This file
-
Clone the repository:
git clone https://github.com/yourusername/quickstart-chat.git cd quickstart-chat -
Publish the module to SpacetimeDB:
cd server spacetime publish
spacetime client connect quickstart-chatspacetime call quickstart-chat set_name "YourUsername"spacetime call quickstart-chat send_message "Hello, World!"spacetime logs quickstart-chatspacetime sql quickstart-chat "SELECT * FROM message"spacetime sql quickstart-chat "SELECT * FROM user"The User table stores information about connected users:
identity: Primary key, unique identifier for each username: Optional usernameonline: Boolean indicating if the user is currently online
The Message table stores chat messages:
sender: Identity of the user who sent the messagesent: Timestamp when the message was senttext: Content of the message
Sets the name for the current user.
Sends a message to the chat room.
Automatically called when a client connects to the database.
Automatically called when a client disconnects from the database.
- spacetimedb v1.1.2
- log v0.4
Contributions are welcome! Please feel free to submit a Pull Request.