Schemas — typed fields & required checks

Register a schema for an entity and every write is validated before it lands. MQDB checks types (string, number, boolean, array, object), enforces required fields, and fills in any default values you declare.

How it works

flowchart TD
    W["db.create(entity, data)"] --> S{schema?}
    S -- no schema --> OK[write]
    S -- has schema --> V{per-field
validate} V -- required missing --> R1[reject] V -- wrong type --> R2[reject] V -- missing
(has default) --> F[fill default] --> OK V -- all present,
types ok --> OK style R1 fill:#ffcdd2,stroke:#c62828 style R2 fill:#ffcdd2,stroke:#c62828 style OK fill:#c8e6c9,stroke:#2e7d32 style F fill:#fff3e0,stroke:#ef6c00

Try it — a four-step tour

  1. The Schema Builder is pre-filled with 4 fields (name, email, age, active). Click Add schema.
  2. Click the four preset scenarios on the right. Two succeed, two fail — each shows a concrete example of what the validator enforces.
  3. Add a new field via + Add field (e.g. role, type string, default 'user'), click Add schema again, then re-run the Default value preset — the record gets role: 'user' automatically.
  4. Click Run all tests to see the 5 automated checks.

Schema builder

Fields

Name
Type
Required
Default

Preset scenarios

Each preset uses the users schema above. Run them one after another to see validator behaviour.

1 · Valid data

{ name: "Alice", email: "alice@example.com", age: 30 }

2 · Wrong type

{ name: "Bob", email: "bob@x.com", age: "thirty" }

3 · Missing required

{ name: "Charlie" } // no email

4 · Default value applied

{ name: "Diana", email: "diana@x.com" } // → active=true

Manual write

Registered schemas 0

No schemas yet.

Automated test suite

Run all tests creates a test_users schema and runs these 5 steps:

  1. Valid data is accepted
  2. Wrong type (age as string) is rejected
  3. Missing required (email) is rejected
  4. Default value is applied when field is omitted
  5. getSchema returns the exact 4-field definition
Click the button to run.

Log