Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

REPL

The REPL (Read-Eval-Print Loop) is a powerful interface that allows ROOT users to interact directly with the underlying database system in Kinesis API. This advanced feature provides a command-line style interface for executing database operations, testing queries, and managing data structures without leaving the web interface.

Access Control

⚠️ Important: The REPL interface is only accessible to users with the ROOT role. This restriction is in place because the REPL provides direct access to the database, bypassing the standard API permissions and validations.

Accessing the REPL

To access the REPL interface:

  1. Log in with a ROOT user account
  2. Navigate to /web/repl in your browser or select "REPL" from the navigation menu

REPL Interface

REPL Interface

The REPL interface consists of:

  1. Command Input Area: A textarea where you can enter database commands
  2. Output Format Selector: Choose between Table, JSON, and Standard output formats
  3. Execute Button: Run the entered command
  4. Output Display: Shows the results of executed commands

Available Commands

The REPL supports a comprehensive set of commands for interacting with the database:

Table Management

CommandDescriptionExample
CREATE_TABLECreate a new table with optional schemaCREATE_TABLE users name STRING --required age INTEGER
DROP_TABLEDelete a tableDROP_TABLE users
GET_TABLEShow table schemaGET_TABLE users
GET_TABLESList all tablesGET_TABLES
UPDATE_SCHEMAUpdate table schemaUPDATE_SCHEMA users --version=2 active BOOLEAN

Record Management

CommandDescriptionExample
INSERTInsert a new recordINSERT INTO users ID 1 SET name = "John" age = 30
UPDATEUpdate an existing recordUPDATE users ID 1 SET age = 31
DELETEDelete a recordDELETE FROM users 1
GET_RECORDRetrieve a single recordGET_RECORD FROM users 1
GET_RECORDSRetrieve all records from a tableGET_RECORDS FROM users
SEARCH_RECORDSSearch for recordsSEARCH_RECORDS FROM users MATCH "John"

Help

CommandDescriptionExample
HELPShow general helpHELP
HELP [command]Show help for a specific commandHELP CREATE_TABLE

Output Formats

The REPL supports three output formats:

  1. Table: Formats results as ASCII tables for easy reading
  2. JSON: Returns results in JSON format for programmatic analysis
  3. Standard: Simple text output with minimal formatting

Using the REPL

Basic Usage

  1. Enter a command in the input area
  2. Select your preferred output format
  3. Click "Execute" to run the command
  4. View the results in the output display

Schema Definition

When creating or updating tables, you can define schema fields with various constraints:

CREATE_TABLE users
  name STRING --required --min=2 --max=50
  email STRING --required --unique --pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
  age INTEGER --min=0 --max=120

Available field types:

  • STRING: Text data
  • INTEGER: Whole numbers
  • FLOAT: Decimal numbers
  • BOOLEAN: True/false values

Available field constraints:

  • --required: Field must have a value
  • --unique: Field values must be unique within the table
  • --min=<value>: Minimum value (for numbers) or length (for strings)
  • --max=<value>: Maximum value (for numbers) or length (for strings)
  • --pattern=<regex>: Regular expression pattern for string validation
  • --default=<value>: Default value if none is provided

Security Considerations

The REPL provides direct access to the database, which comes with significant power and responsibility:

  1. Limited Access: Only ROOT users can access the REPL
  2. Audit Trail: All REPL commands are logged in the system events
  3. No Undo: Most operations cannot be undone, especially schema changes and deletions
  4. Performance Impact: Complex queries on large tables may impact system performance

Best Practices

  1. Test in Development: Use the REPL in development environments before running commands in production
  2. Back Up First: Create backups before making significant schema changes
  3. Use Transactions: For complex operations, consider using transactions to ensure data integrity
  4. Document Changes: Keep records of schema changes made through the REPL
  5. Prefer API: For routine operations, use the standard API endpoints rather than direct REPL access

Example Use Cases

The REPL is particularly useful for:

  1. Prototyping: Quickly create and test database structures
  2. Data Cleanup: Fix or remove problematic records
  3. Schema Evolution: Add or modify fields in existing tables
  4. Troubleshooting: Inspect database contents for debugging
  5. Data Migration: Bulk operations during system updates
  • Kinesis DB - Learn about the underlying database system