Skip to content

infinia-yzl/quickstart-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuickStart Chat

A simple chat application built with SpacetimeDB.

Description

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.

Project Structure

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

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/quickstart-chat.git
    cd quickstart-chat
  2. Publish the module to SpacetimeDB:

    cd server
    spacetime publish

Usage

Connect to the chat application

spacetime client connect quickstart-chat

Set your username

spacetime call quickstart-chat set_name "YourUsername"

Send a message

spacetime call quickstart-chat send_message "Hello, World!"

View logs

spacetime logs quickstart-chat

Query messages

spacetime sql quickstart-chat "SELECT * FROM message"

Query users

spacetime sql quickstart-chat "SELECT * FROM user"

Data Model

User Table

The User table stores information about connected users:

  • identity: Primary key, unique identifier for each user
  • name: Optional username
  • online: Boolean indicating if the user is currently online

Message Table

The Message table stores chat messages:

  • sender: Identity of the user who sent the message
  • sent: Timestamp when the message was sent
  • text: Content of the message

Reducers

set_name

Sets the name for the current user.

send_message

Sends a message to the chat room.

client_connected

Automatically called when a client connects to the database.

client_disconnected

Automatically called when a client disconnects from the database.

Dependencies

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

SpacetimeDB quickstart tutorial: https://spacetimedb.com/docs/modules/rust/quickstart

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages