Rullst AcademyRullst Academy/Lesson
Applications with Rullst I · Lesson 07 / 14

Persistence: store with rules

A mission needs to survive the end of the process.

Learning paths18 min

Let's discover together

  1. 1

    Store opens a SQLite connection and executes schema.sql. The STRICT table requires compatible types; NOT NULL and CHECK reinforce rules. INTEGER PRIMARY KEY identifies each mission, while done accepts only 0 or 1. A title is not identity: two missions may share a name.

  2. 2

    The app uses one connection to keep the lab small. Parameterized queries and database constraints complement Rust validation. Not every rule is duplicated in CHECK: control characters, for example, are rejected by Rust. Inspect each rule rather than assuming equivalence.

  3. 3

    Create three missions, stop with Ctrl+C and run again in the same folder. The list should return. Tests use :memory: for isolated cases; closing that connection loses its data. File persistence and in-memory test databases serve different purposes.

  4. 4

    PRAGMA user_version records schema 1. The kit rejects higher versions but is not a full migration platform. CREATE TABLE IF NOT EXISTS only creates missing tables: editing schema.sql does not transform old tables. Plan migration and backup before evolving existing data.

Your application workbench

The kit includes a complete app to investigate and modify. The excerpt below explains this step; the editor contains the indicated file. Rullst Academy does not compile or run this server in your browser.

File to study and modify

schema.sql

CREATE TABLE missions (
  id INTEGER PRIMARY KEY,
  title TEXT NOT NULL CHECK(length(trim(title)) BETWEEN 1 AND 80),
  priority INTEGER NOT NULL CHECK(priority BETWEEN 1 AND 3),
  done INTEGER NOT NULL DEFAULT 0 CHECK(done IN (0,1))
) STRICT;

Extract the kit to a new folder and open a terminal beside Cargo.toml. Use Rust 1.96+; the first build may download dependencies and take time. Then open http://127.0.0.1:3010. Stop with Ctrl+C and run again after editing.

cargo test --locked
cargo run --locked
My files and GitHub

Download your draft and replace the indicated file in your extracted copy. The editor saves one file in this browser; your account saves assessments and XP. The ZIP excludes your edits. GitHub sends only the confirmed file; use Git manually for the whole app, excluding databases, backups and secrets.

Official links and next step

✦
YOUR MISSION

Explain schema, file and constraints; verify data after restarting.

Now it's your turn

Discovery workshop

Decide before running

Explain schema, file and constraints; verify data after restarting.
Build your answers and check when you are ready.
A moment to understand

What helps distinguish two missions named Orbit?

I need a hint

Order can change; id directs an update to the correct record.

Loading your journey…

Take it with you

Compare an in-memory test with a file-backed run. Record the file location and which rules belong to Rust and SQL. Try an invalid constraint only in a new test database.

At your own pace

My files and GitHub

Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

Student guide

The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

Checking your access to this lesson…

Rullstpetbot

AI can make mistakes. Check the lesson material.