Skip to main content

Defining Schema Structure

Drafta uses a flexible schema system to define, structure, and manipulate data. This document provides an overview of the basic syntax required to work with Drafta's schema.

Schema Definition

A schema in Drafta is defined using a YAML structure that outlines the fields and their types. Each top-level entry in the schema represents a 'table' or 'object,' which acts as a structured collection of related fields.

Example Schema

UserProfile:
id: string
name: string
email: string
age: number

Address:
street: string
city: string
zip: string
state: string

Field Types

Drafta supports the following primitive data types for defining schema fields:

  • string: Textual data.
  • number: Numeric values, including integers and floats.
  • boolean: true or false values.
  • enum: A predefined set of possible values.

Nested Objects

Schemas support nested objects for hierarchical data structures.

Example:

BlogPost:
title: string
author:
name: string
email: string

Arrays

Fields can be arrays of a specific type.

Example:

Product:
tags: [string]

Enums

Enum fields allow for predefined sets of values.

Example:

OrderStatus:
status: enum(pending, shipped, delivered, canceled)