Documentation
3. Tables and Schema
Developer-focused documentation with concepts, function details, examples, outputs and SQL comparisons.
Creating tables and columns
db = RelPy()
db.create_table("users")
db.add_column("users", "id", AutoNumber, is_primary_key=True)
db.add_column("users", "name", str, nullable=False)
db.add_column("users", "email", str, nullable=False, is_pii=True, is_encrypted=True)| Function | Purpose | Returns |
|---|---|---|
create_table(table_name) | Creates an empty relation and initializes storage. | self |
add_column(...) | Adds typed metadata and constraints to a table. | self |
set_primary_key(...) | Sets a single or composite primary key using existing columns. | self |
add_column parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
table_name | str | required | Existing table. |
column_name | str | required | New column name. Must be identifier-like. |
data_type | type | required | Python type such as int, str, float, bool or AutoNumber. |
is_primary_key | bool | False | Marks a single-column primary key. |
is_pii | bool | False | Metadata that marks personal data. |
is_encrypted | bool | False | Encrypts stored values and masks exports by default. |
references | str | None | None | Foreign key target such as "users.id". |
on_delete | str | None | None | RESTRICT, CASCADE or SET NULL. |
nullable | bool | None | None | Regular columns default to nullable. Primary keys default to not nullable. |
default | Any | not set | Used when an inserted row omits the column. |
Primary keys and foreign keys
db.add_column("orders", "id", AutoNumber, is_primary_key=True)
db.add_column("orders", "user_id", int, nullable=False, references="users.id", on_delete="CASCADE")CREATE TABLE orders (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);Foreign keys allow automatic join inference and relational delete behavior.
Schema inspection
db.describe_table("users")
db.describe_schema()
db.to_ddl()
db.table_to_ddl("users")Use these functions to inspect the object or export a schema sketch.