The jasonisnthappy REPL (Read-Eval-Print Loop) provides an interactive shell for exploring and managing databases. It’s similar to the MongoDB shell or Redis CLI.
Starting the REPL
There are two ways to enter interactive mode:
Using --interactive flag
Implicit (database path only)
Short form
jasonisnthappy mydb.db --interactive
With web UI
Launch the REPL with the built-in web interface:
jasonisnthappy mydb.db --interactive --web-ui
REPL prompt
The prompt changes based on context:
db > # No collection selected
users > # Collection 'users' is active
Available commands
Database commands
Show database info
List all collections
Show metrics
Create backup
Collection commands
Select a collection
Create new collection
Drop current collection
After using use <collection>, the prompt changes to show the active collection name.
Document commands
All document commands operate on the currently selected collection:
Insert document
Find all documents
Find with query
Count documents
Update documents
Delete documents
users > insert {"name":"Alice","age":30}
Index commands
List indexes
Create index
Create unique index
Import/export
Export collection
Import into collection
users > export users_backup.json
Help and exit
Press Ctrl+C to cancel the current line. Press Ctrl+D or type exit to quit.
Example session
Here’s a typical REPL workflow:
Basic workflow
Creating data
Updating data
$ jasonisnthappy mydb.db
jasonisnthappy interactive shell
Database: mydb.db
Type 'help' for available commands, 'exit' to quit
db > collections
Collections (2):
• users (45 documents )
• orders (123 documents )
db > use users
✓ Now using collection 'users'
users > find {"age":{" $gte ":30}}
Found 12 documents:
Document ID: 1
{
"name" : "Alice",
"age" : 30,
"email" : "alice@example.com"
}
Document ID: 5
{
"name" : "Bob",
"age" : 35,
"email" : "bob@example.com"
}
users > count {"age":{" $gte ":30}}
Count: 12 documents
users > exit
$ jasonisnthappy newdb.db -i
jasonisnthappy interactive shell
Database: newdb.db
db > create users
✓ Collection 'users' created successfully
db > use users
✓ Now using collection 'users'
users > insert {"name":"Alice","email":"alice@example.com","age":30}
✓ Document inserted
Collection: users
ID: 1
users > insert {"name":"Bob","email":"bob@example.com","age":25}
✓ Document inserted
Collection: users
ID: 2
users > create-index email --unique
✓ Index created on field 'email'
Collection: users
Unique: true
Documents indexed: 2
users > find
Found 2 documents:
Document ID: 1
{
"name" : "Alice",
"email" : "alice@example.com",
"age" : 30
}
Document ID: 2
{
"name" : "Bob",
"email" : "bob@example.com",
"age" : 25
}
db > use users
✓ Now using collection 'users'
users > find {"name":"Alice"}
Found 1 document:
Document ID: 1
{
"name" : "Alice",
"age" : 30,
"status" : "active"
}
users > update {"name":"Alice"} {" $set ":{"age":31,"city":"Boston"}}
✓ Documents updated
Collection: users
Matched: 1
Modified: 1
users > find {"name":"Alice"}
Found 1 document:
Document ID: 1
{
"name" : "Alice",
"age" : 31,
"status" : "active",
"city" : "Boston"
}
users > delete {"status":"inactive"}
✓ Documents deleted
Collection: users
Deleted: 3
REPL features
Command history
The REPL maintains a command history that persists between sessions:
Press ↑ (up arrow) to navigate to previous commands
Press ↓ (down arrow) to navigate to next commands
Type and press ↑ to search history for matching commands
Line editing
Full readline support is available:
Ctrl+A - Move to beginning of line
Ctrl+E - Move to end of line
Ctrl+K - Delete from cursor to end of line
Ctrl+U - Delete from cursor to beginning of line
Ctrl+W - Delete word before cursor
Auto-completion
Command names are automatically completed (future feature).
Set the default output format when starting the REPL:
Pretty format (default)
JSON format
Table format
jasonisnthappy mydb.db -i --format pretty
The format applies to all REPL commands. Use --format json for scriptable output.
Working with JSON
Multi-line JSON
The REPL automatically detects incomplete JSON and allows multi-line input:
users > insert {
... "name": "Alice",
... "profile": {
... "age": 30,
... "city": "Boston"
... }
... }
✓ Document inserted
Complex queries
Complex queries can span multiple lines:
users > find {
... " $or ": [
... {"age": {" $lt ": 18 }},
... {"age": {" $gte ": 65 }}
... ],
... "status": "active"
... }
Tips and tricks
Quick database inspection : Run jasonisnthappy mydb.db without -i to see database info and exit immediately.
Test queries safely : Use find to preview documents before running update or delete commands.
Export for backup : Regularly export important collections with export <file> for point-in-time backups.
Check before dropping : Run count or find before drop to verify you’re deleting the right collection.
Error handling
The REPL provides friendly error messages:
users > insert {invalid json}
✗ Error: Invalid JSON: expected value at line 1 column 2
db > use
✗ Usage: use < collectio n >
users > update {"name":"Alice"}
✗ Usage: update {query} {update}
Comparison with CLI commands
REPL commands are simpler than full CLI commands:
db > use users
users > find {"age":{" $gte ":25}}
users > insert {"name":"Alice"}
jasonisnthappy mydb.db doc find users '{"age":{"$gte":25}}'
jasonisnthappy mydb.db doc insert users '{"name":"Alice"}'
The REPL is ideal for exploration and development. Use CLI commands for automation and scripting.
Document commands Full CLI syntax for documents
Database commands Full CLI syntax for databases