Getting Started with OstrichDB CLI
Getting Started with OstrichDB CLI
Section titled “Getting Started with OstrichDB CLI”The OstrichDB CLI is a powerful, lightweight database management tool built from scratch and written in Odin. It provides an intuitive query structure, hierarchical data organization, and built-in security systems, making it ideal for developers seeking an easy-to-use, flexible, high-performance database solution directly from the terminal.
Overview
Section titled “Overview”What is the OstrichDB CLI?
Section titled “What is the OstrichDB CLI?”The OstrichDB CLI is a terminal-based database management system that offers:
- Direct Terminal Access: Manage your database directly from the command line
- Intuitive Query Language: Simple, readable query syntax using dot notation
- Hierarchical Data Structure: Organized data in Collections → Clusters → Records
- Built-in Security: User authentication, role-based access, and database encryption
- Multiple Interaction Methods: CLI queries, HTTP server, and natural language processing
- High Performance: Native compiled code for maximum speed
- Cross-Platform: Support for macOS and Linux systems
Key Features
Section titled “Key Features”- 🖥️ Three Ways to Interact:
- Manual query entry via command-line interface
- Built-in HTTP server for client applications
- Experimental natural language processing
- 🔐 Security First: User authentication, role-based access, database permissions and encryption
- 📊 Hierarchical Data: Custom three-level data structure (Collections → Clusters → Records)
- 📁 File Import: CSV and JSON file importing capabilities
- 🔗 Query Chaining: Execute multiple queries in sequence
- ⚡ Performance Tools: Built-in benchmarking, configurations, and query history
- 🌐 Cross-Platform: macOS and Linux support
Understanding the Data Structure
Section titled “Understanding the Data Structure”OstrichDB organizes data into three hierarchical levels:
Data Hierarchy
Section titled “Data Hierarchy”Collection (.ostrichdb files)└── Cluster (Named groups with IDs) └── Record (name:type:value format)
Collections:
- Database files with
.ostrichdb
extension - Top-level containers for related data
- Can be encrypted, locked, or isolated
Clusters:
- Groups of related records within collections
- Given a name and ID upon creation
- Logical organization within collections
Records:
- Smallest unit of data storage
- Format:
[name] : [type] : [value]
- Strongly typed with validation
Practical Example
Section titled “Practical Example”# A company database structurestaff.ostrichdb # Collection├── engineering # Cluster│ ├── team_lead: STRING: "Alice" # Record│ ├── members: []STRING: "Bob,Carol,Dave" # Record│ └── budget: INTEGER: 50000 # Record└── marketing # Cluster ├── manager: STRING: "Eve" # Record └── campaigns: INTEGER: 3 # Record
Query Language Basics
Section titled “Query Language Basics”CLP Structure
Section titled “CLP Structure”OstrichDB queries use CLPs (Command, Location, Parameter) tokens for clarity:
- (C)ommand Token: Operation to perform (
NEW
,FETCH
,ERASE
) - (L)ocation Token: Dot notation path (
collection.cluster.record
) - (P)arameter Token: Additional modifiers (
OF_TYPE
,WITH
,TO
)
Basic Query Examples
Section titled “Basic Query Examples”# Create a new recordNEW staff.engineering.team_lead OF_TYPE STRING WITH "Alice"
# Fetch dataFETCH staff.engineering.team_lead
# Create with automatic structureNEW inventory.electronics.laptops OF_TYPE INTEGER WITH 25
# Rename objectsRENAME staff.engineering TO development
# Count objectsCOUNT RECORDS
# Get helpHELP NEW
First Steps
Section titled “First Steps”1. Start the CLI
Section titled “1. Start the CLI”After installation, launch OstrichDB:
./main.bin
2. Create Your First Database
Section titled “2. Create Your First Database”# Create a simple user databaseNEW users.active.john_doe OF_TYPE STRING WITH "John Doe"NEW users.active.john_email OF_TYPE STRING WITH "john@example.com"NEW users.active.john_age OF_TYPE INTEGER WITH 30
# View the data structureTREE
# Fetch user dataFETCH users.active.john_doeFETCH users.active
3. Explore Basic Operations
Section titled “3. Explore Basic Operations”# Create additional recordsNEW users.active.jane_doe OF_TYPE STRING WITH "Jane Smith"NEW users.inactive.old_user OF_TYPE STRING WITH "Former Employee"
# Count records in different clustersCOUNT RECORDS IN users.activeCOUNT RECORDS IN users.inactive
# Get collection informationSIZE_OF usersCOUNT CLUSTERS IN users
# Search for recordsWHERE john
4. Learn Query Chaining
Section titled “4. Learn Query Chaining”# Execute multiple operations togetherNEW products.electronics.laptop OF_TYPE INTEGER WITH 5 && FETCH products.electronics.laptop
# Chain operations across different collectionsNEW inventory.warehouse.location OF_TYPE STRING WITH "Building A" && COUNT RECORDS IN inventory.warehouse && TREE
Three Interaction Methods
Section titled “Three Interaction Methods”1. Direct CLI Queries
Section titled “1. Direct CLI Queries”The primary method - enter queries directly in the terminal:
OstrichDB> NEW blog.posts.welcome OF_TYPE STRING WITH "Welcome to my blog!"OstrichDB> FETCH blog.posts.welcomeOstrichDB> COUNT RECORDS IN blog.posts
2. HTTP Server Mode
Section titled “2. HTTP Server Mode”Enable the built-in server for application integration:
# Start the serverOstrichDB> SERVE
# Server runs on default port 8080# Make HTTP requests from your applicationscurl http://localhost:8080/api/...
3. Natural Language Processing (Experimental)
Section titled “3. Natural Language Processing (Experimental)”Use natural language queries:
# Start the agent (requires server running in another terminal)OstrichDB> AGENT
# Then use natural language"Create a new user record for Alice with email alice@example.com""Show me all products in the electronics category""Delete the old test data"
Common Use Cases
Section titled “Common Use Cases”Personal Data Management
Section titled “Personal Data Management”# Personal finance trackerNEW finances.income.salary OF_TYPE FLOAT WITH 5000.00NEW finances.expenses.rent OF_TYPE FLOAT WITH 1200.00NEW finances.expenses.utilities OF_TYPE []FLOAT WITH 200.00,150.00,100.00
# View financial summaryFETCH finances.incomeFETCH finances.expenses
Development Project Tracking
Section titled “Development Project Tracking”# Project managementNEW projects.webapp.status OF_TYPE STRING WITH "In Progress"NEW projects.webapp.team_size OF_TYPE INTEGER WITH 3NEW projects.webapp.technologies OF_TYPE []STRING WITH "React,Node.js,OstrichDB"NEW projects.webapp.deadline OF_TYPE DATE WITH 2024-06-15
# Track progressFETCH projects.webappCOUNT RECORDS IN projects.webapp
Inventory Management
Section titled “Inventory Management”# Store inventoryNEW inventory.electronics.laptops OF_TYPE INTEGER WITH 25NEW inventory.electronics.phones OF_TYPE INTEGER WITH 50NEW inventory.books.fiction OF_TYPE INTEGER WITH 200NEW inventory.books.technical OF_TYPE INTEGER WITH 75
# Check stock levelsFETCH inventory.electronicsCOUNT COLLECTIONSSIZE_OF inventory
Session Management
Section titled “Session Management”User Authentication
Section titled “User Authentication”# Create new user (if needed)NEW USER
# Login/logout# (Authentication handled automatically on startup)LOGOUT
# View command historyHISTORY
# Clear sessionCLEAR
Session Tools
Section titled “Session Tools”# View current data structureTREE
# Check performanceBENCHMARK
# Get version informationVERSION
# Exit the CLIEXIT
Best Practices
Section titled “Best Practices”1. Naming Conventions
Section titled “1. Naming Conventions”Use clear, descriptive names:
# Good namingNEW company.employees.john_smith_email OF_TYPE STRING WITH "john@company.com"NEW inventory.products.laptop_dell_xps OF_TYPE INTEGER WITH 10
# Avoid unclear namesNEW stuff.things.data OF_TYPE STRING WITH "something"
2. Data Organization
Section titled “2. Data Organization”Structure data logically:
# Organize by domainNEW users.active.*NEW users.inactive.*NEW products.electronics.*NEW products.books.*
# Group related dataNEW blog.posts.*NEW blog.comments.*NEW blog.authors.*
3. Use Query Chaining Efficiently
Section titled “3. Use Query Chaining Efficiently”# Efficient: Related operations togetherNEW users.staff.alice OF_TYPE STRING WITH "Alice Johnson" && NEW users.staff.alice_role OF_TYPE STRING WITH "Developer" && COUNT RECORDS IN users.staff
# Less efficient: Separate queries for related dataNEW users.staff.alice OF_TYPE STRING WITH "Alice Johnson"NEW users.staff.alice_role OF_TYPE STRING WITH "Developer"COUNT RECORDS IN users.staff
4. Regular Maintenance
Section titled “4. Regular Maintenance”# Regular housekeepingCOUNT COLLECTIONSSIZE_OF large_collectionVALIDATE collection_name
# Create backupsBACKUP important_collection
# Monitor performanceBENCHMARK collection_operations
Getting Help
Section titled “Getting Help”Built-in Help System
Section titled “Built-in Help System”# General helpHELP
# Specific command helpHELP NEWHELP FETCHHELP COUNT
# View all available commandsHELP COMMANDS
Troubleshooting
Section titled “Troubleshooting”# Validate collections for errorsVALIDATE collection_name
# Check data structureTREE
# View command history for debuggingHISTORY
# Restart if neededRESTART
Next Steps
Section titled “Next Steps”Now that you understand the basics:
- Install OstrichDB CLI - Set up your development environment
- Learn Query Structure - Master the CLP system and dot notation
- Explore Commands - Complete reference of all available commands
- Understand Data Types - Work with different data types effectively
- Configure Your Setup - Customize OstrichDB for your workflow
The OstrichDB CLI provides a powerful, direct way to manage hierarchical data with an intuitive query language. Whether you’re prototyping, managing personal data, or building applications, the CLI offers the flexibility and performance you need.