Complete guide to creating bundles (collections/tables) in SyndrDB.
The CREATE BUNDLE statement creates a new bundle with defined fields and constraints.
Standard Syntax:
CREATE BUNDLE "<BUNDLE_NAME>"
WITH FIELDS (
{"<FIELD_NAME>", "<FIELD_TYPE>", <IS_REQUIRED>, <IS_UNIQUE>, <DEFAULT_VALUE>},
...
);
Components:
CREATE BUNDLE - Command keywords"<BUNDLE_NAME>" - Name of the bundle (quoted string)WITH FIELDS - Introduces the field definitions( {...}, ... ) - Field definitions in bracesCreate a bundle with one field:
CREATE BUNDLE "users"
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0}
);
Response:
Bundle 'users' created successfully.
Create a bundle with multiple fields:
CREATE BUNDLE "products"
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0},
{"name", "string", TRUE, FALSE, ""},
{"price", "float", TRUE, FALSE, 0.0},
{"active", "bool", FALSE, FALSE, TRUE}
);
💡 Tip: Each field definition is a complete specification enclosed in braces
{ }and separated by commas.
The WITH FIELDS clause specifies the bundle's schema.
Syntax:
WITH FIELDS (
{<field_definition>},
{<field_definition>},
...
)
Requirements:
( ){ }Examples:
Single field:
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0}
)
Multiple fields:
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0},
{"email", "string", TRUE, TRUE, ""},
{"created_at", "datetime", TRUE, FALSE, NULL}
)
Each field definition consists of 5 properties in this exact order:
{"<FIELD_NAME>", "<FIELD_TYPE>", <IS_REQUIRED>, <IS_UNIQUE>, <DEFAULT_VALUE>}
| Position | Property | Type | Description |
|---|---|---|---|
| 1 | Field Name | String | Name of the field |
| 2 | Field Type | String | Data type of the field |
| 3 | Is Required | Boolean | Whether field is mandatory (TRUE/FALSE) |
| 4 | Is Unique | Boolean | Whether field must be unique (TRUE/FALSE) |
| 5 | Default Value | Any | Default value matching field type |
Example:
{"email", "string", TRUE, TRUE, "user@example.com"}
Field names identify fields within documents.
Rules:
Valid Examples:
{"id", ...}
{"user_name", ...}
{"first_name", ...}
{"createdAt", ...}
{"email_address", ...}
Invalid Examples:
{id, ...} -- ❌ Not quoted
{"", ...} -- ❌ Empty string
💡 Best Practice: Use consistent naming conventions (
snake_caseorcamelCase) throughout your schema.
Specifies the data type for the field value.
Syntax:
"<type_name>"
Supported Types:
"string" - Text data"int" - Integer numbers"float" - Decimal numbers"bool" - Boolean (true/false)"datetime" - Date and time valuesExamples:
{"name", "string", TRUE, FALSE, ""}
{"age", "int", TRUE, FALSE, 0}
{"price", "float", TRUE, FALSE, 0.0}
{"active", "bool", FALSE, FALSE, TRUE}
📝 Note: Type names are case-insensitive and normalized to lowercase internally.
Determines whether the field must have a value.
Syntax:
TRUE -- Field is required (cannot be NULL or empty)
FALSE -- Field is optional (can be NULL or empty)
Examples:
Required field:
{"email", "string", TRUE, FALSE, ""}
-- Email must be provided for every document
Optional field:
{"middle_name", "string", FALSE, FALSE, NULL}
-- Middle name can be omitted or NULL
⚠️ Important: Use uppercase
TRUEandFALSE. Lowercase will not be recognized.
Determines whether the field value must be unique across all documents in the bundle.
Syntax:
TRUE -- Field value must be unique
FALSE -- Field value can be duplicated
Examples:
Unique field:
{"email", "string", TRUE, TRUE, ""}
-- No two documents can have the same email
Non-unique field:
{"status", "string", TRUE, FALSE, "active"}
-- Multiple documents can have the same status
💡 Use Case: Use
TRUEfor fields like IDs, email addresses, usernames, or any field that should uniquely identify documents.
The value assigned to the field if no value is provided during document insertion.
Syntax:
<value_matching_field_type>
NULL -- Explicitly no default
Type-Specific Defaults:
String:
{"name", "string", FALSE, FALSE, "Unknown"}
{"status", "string", TRUE, FALSE, "pending"}
Integer:
{"count", "int", FALSE, FALSE, 0}
{"age", "int", FALSE, FALSE, 18}
Float:
{"price", "float", TRUE, FALSE, 0.0}
{"rating", "float", FALSE, FALSE, 5.0}
Boolean:
{"active", "bool", FALSE, FALSE, TRUE}
{"verified", "bool", FALSE, FALSE, FALSE}
NULL (no default):
{"optional_field", "string", FALSE, FALSE, NULL}
📝 Note: Default values must match the field type, otherwise validation will fail.
SyndrDB supports multiple data types for field definitions.
Text data of any length.
Syntax:
"string"
Default Value Examples:
"" -- Empty string
"default text" -- Any text
NULL -- No default
Complete Example:
CREATE BUNDLE "users"
WITH FIELDS (
{"username", "string", TRUE, TRUE, ""},
{"bio", "string", FALSE, FALSE, NULL},
{"status", "string", TRUE, FALSE, "active"}
);
Whole numbers (positive or negative).
Syntax:
"int"
Default Value Examples:
0 -- Zero
42 -- Positive integer
-10 -- Negative integer
NULL -- No default
Complete Example:
CREATE BUNDLE "products"
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0},
{"stock", "int", TRUE, FALSE, 0},
{"min_order", "int", FALSE, FALSE, 1}
);
📝 Note: Integers are stored as
int64internally.
Decimal numbers (floating-point).
Syntax:
"float"
Default Value Examples:
0.0 -- Zero
99.99 -- Positive decimal
-5.5 -- Negative decimal
NULL -- No default
Complete Example:
CREATE BUNDLE "products"
WITH FIELDS (
{"price", "float", TRUE, FALSE, 0.0},
{"discount", "float", FALSE, FALSE, 0.0},
{"rating", "float", FALSE, FALSE, 5.0}
);
📝 Note: Floats are stored as
float64internally.
True or false values.
Syntax:
"bool"
Default Value Examples:
TRUE -- True (boolean)
FALSE -- False (boolean)
NULL -- No default
Complete Example:
CREATE BUNDLE "settings"
WITH FIELDS (
{"dark_mode", "bool", FALSE, FALSE, FALSE},
{"notifications", "bool", FALSE, FALSE, TRUE},
{"auto_save", "bool", TRUE, FALSE, TRUE}
);
⚠️ Important: Use uppercase
TRUEandFALSEfor boolean values.
Date values (year-month-day).
Syntax:
"date"
Default Value Examples:
"2025-01-01" -- ISO date format
NULL -- No default
Complete Example:
CREATE BUNDLE "events"
WITH FIELDS (
{"event_date", "date", TRUE, FALSE, "2025-01-01"},
{"deadline", "date", FALSE, FALSE, NULL}
);
📅 Format: Use ISO 8601 date format:
YYYY-MM-DD
Date and time values.
Syntax:
"datetime"
Default Value Examples:
"2025-01-01T12:00:00Z" -- ISO datetime format with timezone
NULL -- No default
Complete Example:
CREATE BUNDLE "logs"
WITH FIELDS (
{"created_at", "datetime", TRUE, FALSE, "2025-01-01T00:00:00Z"},
{"updated_at", "datetime", FALSE, FALSE, NULL}
);
🕐 Format: Use ISO 8601 datetime format:
YYYY-MM-DDTHH:MM:SSZ
Time values (hours:minutes:seconds).
Syntax:
"time"
Default Value Examples:
"14:30:00" -- 24-hour format
"00:00:00" -- Midnight
NULL -- No default
Complete Example:
CREATE BUNDLE "schedules"
WITH FIELDS (
{"start_time", "time", TRUE, FALSE, "09:00:00"},
{"end_time", "time", TRUE, FALSE, "17:00:00"}
);
⏰ Format: Use 24-hour time format:
HH:MM:SS
JSON objects for structured data.
Syntax:
"json"
Default Value Examples:
"{}" -- Empty JSON object
NULL -- No default
Complete Example:
CREATE BUNDLE "configurations"
WITH FIELDS (
{"settings", "json", FALSE, FALSE, "{}"},
{"metadata", "json", FALSE, FALSE, NULL}
);
💡 Use Case: Store complex nested data structures without predefined schema.
Binary large objects for storing files or binary data.
Syntax:
"blob"
Default Value Examples:
"" -- Empty blob
NULL -- No default
Complete Example:
CREATE BUNDLE "attachments"
WITH FIELDS (
{"file_data", "blob", FALSE, FALSE, ""},
{"thumbnail", "blob", FALSE, FALSE, NULL}
);
📎 Use Case: Store images, PDFs, or any binary file data.
CREATE BUNDLE "users"
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0},
{"username", "string", TRUE, TRUE, ""},
{"email", "string", TRUE, TRUE, ""},
{"password_hash", "string", TRUE, FALSE, ""},
{"first_name", "string", TRUE, FALSE, ""},
{"last_name", "string", TRUE, FALSE, ""},
{"age", "int", FALSE, FALSE, NULL},
{"is_active", "bool", TRUE, FALSE, TRUE},
{"is_verified", "bool", TRUE, FALSE, FALSE},
{"created_at", "datetime", TRUE, FALSE, "2025-01-01T00:00:00Z"},
{"last_login", "datetime", FALSE, FALSE, NULL}
);
Use Case: Complete user profile system with authentication and tracking.
CREATE BUNDLE "products"
WITH FIELDS (
{"sku", "string", TRUE, TRUE, ""},
{"name", "string", TRUE, FALSE, ""},
{"description", "string", FALSE, FALSE, ""},
{"price", "float", TRUE, FALSE, 0.0},
{"cost", "float", FALSE, FALSE, 0.0},
{"stock_quantity", "int", TRUE, FALSE, 0},
{"min_stock", "int", FALSE, FALSE, 10},
{"category", "string", TRUE, FALSE, "general"},
{"is_available", "bool", TRUE, FALSE, TRUE},
{"is_featured", "bool", FALSE, FALSE, FALSE},
{"rating", "float", FALSE, FALSE, 0.0},
{"image_data", "blob", FALSE, FALSE, NULL}
);
Use Case: Product inventory management with pricing and availability tracking.
CREATE BUNDLE "posts"
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0},
{"title", "string", TRUE, FALSE, ""},
{"slug", "string", TRUE, TRUE, ""},
{"content", "string", TRUE, FALSE, ""},
{"excerpt", "string", FALSE, FALSE, ""},
{"author_id", "int", TRUE, FALSE, 0},
{"category", "string", TRUE, FALSE, "uncategorized"},
{"is_published", "bool", TRUE, FALSE, FALSE},
{"view_count", "int", FALSE, FALSE, 0},
{"published_at", "datetime", FALSE, FALSE, NULL},
{"created_at", "datetime", TRUE, FALSE, "2025-01-01T00:00:00Z"},
{"updated_at", "datetime", FALSE, FALSE, NULL},
{"metadata", "json", FALSE, FALSE, "{}"}
);
Use Case: Content management system with publishing workflow.
CREATE BUNDLE "orders"
WITH FIELDS (
{"order_id", "int", TRUE, TRUE, 0},
{"customer_id", "int", TRUE, FALSE, 0},
{"order_date", "date", TRUE, FALSE, "2025-01-01"},
{"order_time", "time", TRUE, FALSE, "00:00:00"},
{"total_amount", "float", TRUE, FALSE, 0.0},
{"discount", "float", FALSE, FALSE, 0.0},
{"tax", "float", FALSE, FALSE, 0.0},
{"status", "string", TRUE, FALSE, "pending"},
{"is_paid", "bool", TRUE, FALSE, FALSE},
{"is_shipped", "bool", TRUE, FALSE, FALSE},
{"tracking_number", "string", FALSE, FALSE, NULL},
{"notes", "string", FALSE, FALSE, ""}
);
Use Case: E-commerce order management with payment and shipping status.
CREATE BUNDLE "settings"
WITH FIELDS (
{"key", "string", TRUE, TRUE, ""},
{"value", "string", TRUE, FALSE, ""},
{"description", "string", FALSE, FALSE, ""}
);
Use Case: Application configuration key-value store.
CREATE BUNDLE "tags" WITH FIELDS ({"id", "int", TRUE, TRUE, 0}, {"name", "string", TRUE, TRUE, ""});
Use Case: Single-line format for simple bundles.
✅ CORRECT: CREATE BUNDLE "users" WITH FIELDS (...)
❌ INCORRECT: CREATE BUNDLE users WITH FIELDS (...)
✅ CORRECT: {"name", "string", TRUE, FALSE, ""}
❌ INCORRECT: {name, string, TRUE, FALSE, ""}
✅ CORRECT: {"active", "bool", TRUE, FALSE, FALSE}
❌ INCORRECT: {"active", "bool", true, false, false}
Every bundle must have at least one field definition.
✅ CORRECT:
CREATE BUNDLE "users" WITH FIELDS (
{"id", "int", TRUE, TRUE, 0}
);
❌ INCORRECT:
CREATE BUNDLE "users" WITH FIELDS ();
Always include a unique identifier field:
{"id", "int", TRUE, TRUE, 0}
-- or
{"uuid", "string", TRUE, TRUE, ""}
Match data types to your data:
✅ CORRECT: {"age", "int", ...}
❌ AVOID: {"age", "string", ...}
✅ CORRECT: {"price", "float", ...}
❌ AVOID: {"price", "string", ...}
Provide sensible defaults:
✅ GOOD: {"status", "string", TRUE, FALSE, "pending"}
❌ AVOID: {"status", "string", TRUE, FALSE, ""}
✅ GOOD: {"quantity", "int", FALSE, FALSE, 0}
✅ GOOD: {"optional", "string", FALSE, FALSE, NULL}
Choose one naming style and stick to it:
✅ SNAKE_CASE (recommended):
{"first_name", "string", TRUE, FALSE, ""}
{"last_name", "string", TRUE, FALSE, ""}
✅ CAMELCASE (also valid):
{"firstName", "string", TRUE, FALSE, ""}
{"lastName", "string", TRUE, FALSE, ""}
❌ MIXED (avoid):
{"first_name", "string", TRUE, FALSE, ""}
{"lastName", "string", TRUE, FALSE, ""}
Both formats are valid:
✅ WITH semicolon: CREATE BUNDLE "users" WITH FIELDS (...);
✅ WITHOUT semicolon: CREATE BUNDLE "users" WITH FIELDS (...)
Format complex bundles with multiple lines:
✅ READABLE:
CREATE BUNDLE "users"
WITH FIELDS (
{"id", "int", TRUE, TRUE, 0},
{"email", "string", TRUE, TRUE, ""},
{"name", "string", TRUE, FALSE, ""}
);
❌ HARD TO READ:
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE, TRUE, 0}, {"email", "string", TRUE, TRUE, ""}, {"name", "string", TRUE, FALSE, ""});
❌ ERROR:
CREATE BUNDLE WITH FIELDS ({"id", "int", TRUE, TRUE, 0});
Error Message:
invalid CREATE BUNDLE command syntax
Solution:
✅ CORRECT:
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE, TRUE, 0});
❌ ERROR:
CREATE BUNDLE "users" ({"id", "int", TRUE, TRUE, 0});
Error Message:
WITH FIELDS section not found in CREATE BUNDLE command
Solution:
✅ CORRECT:
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE, TRUE, 0});
❌ ERROR:
CREATE BUNDLE "users" WITH FIELDS ();
Error Message:
CREATE BUNDLE must specify at least one field
Solution:
✅ CORRECT:
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE, TRUE, 0});
❌ ERROR:
CREATE BUNDLE "users" WITH FIELDS ({id, "int", TRUE, TRUE, 0});
Error Message:
field name must be a string
Solution:
✅ CORRECT:
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE, TRUE, 0});
❌ ERROR:
CREATE BUNDLE "users" WITH FIELDS ({"id", int, TRUE, TRUE, 0});
Error Message:
field type must be a string
Solution:
✅ CORRECT:
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE, TRUE, 0});
❌ ERROR:
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE});
Error Message:
field definition must have name, type, required, and unique properties
Solution:
✅ CORRECT (all 5 properties):
CREATE BUNDLE "users" WITH FIELDS ({"id", "int", TRUE, TRUE, 0});
❌ ERROR:
CREATE BUNDLE "users" WITH FIELDS (
{"id", "int", TRUE, TRUE, 0}
{"name", "string", TRUE, FALSE, ""}
);
Error Message:
expected comma or closing parenthesis
Solution:
✅ CORRECT:
CREATE BUNDLE "users" WITH FIELDS (
{"id", "int", TRUE, TRUE, 0},
{"name", "string", TRUE, FALSE, ""}
);
❌ ERROR:
CREATE BUNDLE "my bundle!" WITH FIELDS (...);
Error Message:
invalid bundle name 'my bundle!': contains invalid characters
Solution:
✅ CORRECT:
CREATE BUNDLE "my_bundle" WITH FIELDS (...);
💡 Allowed characters: Letters, numbers, underscores (
_), and hyphens (-). No spaces or special characters.
❌ ERROR:
CREATE BUNDLE "users" WITH FIELDS (...);
-- Then running again:
CREATE BUNDLE "users" WITH FIELDS (...);
Error Message:
bundle 'users' already exists
Solution: Use a different bundle name or delete the existing bundle first.
Once a bundle is created, you can:
Add documents:
ADD DOCUMENT TO BUNDLE "users" WITH ({"name" = "Alice"});
Query documents:
SELECT * FROM "users";
Create indexes:
CREATE HASH INDEX "users_email_idx" ON BUNDLE "users" ("email");
Add relationships:
UPDATE BUNDLE "users" ADD RELATIONSHIP ("1toMany", "users", "id", "orders", "user_id");
Verify the bundle was created successfully:
SHOW BUNDLE "users";
Expected Output:
Bundle: users
Fields:
- id (int, required, unique)
- email (string, required, unique)
- name (string, required)
| Component | Syntax | Example |
|---|---|---|
| Basic CREATE | CREATE BUNDLE "name" WITH FIELDS (...) |
CREATE BUNDLE "users" WITH FIELDS (...) |
| Field Definition | {"name", "type", req, uniq, default} |
{"email", "string", TRUE, TRUE, ""} |
| String Type | "string" |
{"name", "string", TRUE, FALSE, ""} |
| Integer Type | "int" |
{"age", "int", FALSE, FALSE, 0} |
| Float Type | "float" |
{"price", "float", TRUE, FALSE, 0.0} |
| Boolean Type | "bool" |
{"active", "bool", FALSE, FALSE, TRUE} |
| Date Type | "date" |
{"created", "date", TRUE, FALSE, "2025-01-01"} |
| Datetime Type | "datetime" |
{"timestamp", "datetime", TRUE, FALSE, "2025-01-01T00:00:00Z"} |
| Time Type | "time" |
{"start", "time", TRUE, FALSE, "09:00:00"} |
| JSON Type | "json" |
{"data", "json", FALSE, FALSE, "{}"} |
| Blob Type | "blob" |
{"file", "blob", FALSE, FALSE, ""} |
| Required | TRUE |
Required field (cannot be NULL) |
| Optional | FALSE |
Optional field (can be NULL) |
| Unique | TRUE |
Value must be unique across bundle |
| Non-Unique | FALSE |
Value can be duplicated |
| NULL Default | NULL |
No default value |
For more information:
Last updated: November 20, 2025 🚀