Introducing sqd: A SQL-Like Document Editor
I’ve always been frustrated with the inconsistent syntax across grep, sed, and awk. Each tool has its own flags, regex patterns, and quirks that I constantly have to look up. So I built sqd, a tool that lets you query and edit text files using familiar SQL-like commands.
What is sqd?
sqd is a CLI tool written in GO that treats text files like databases. Instead of remembering different command-line flags and regex patterns, you write SQL-like queries to search, count, update, or delete content across multiple files. Here are some examples of what you can do:
Count all the LaTeX formulas in your notes:
sqd 'SELECT count(*) FROM * WHERE content LIKE "%$$"'Refactor your markdown title hierarchy:
sqd 'UPDATE *.md SET content="### " WHERE content LIKE "## %"'Batch multiple updates in a single command:
sqd 'UPDATE example.md
SET content="## Title 1 UPDATED" WHERE content = "## Title 1 to be updated",
SET content="## Title 2 UPDATED" WHERE content = "## Title 2 TO be updated"'The tool works recursively on file globs, supports batch operations, and has zero external dependencies. I built it primarily for my own workflow, especially for managing my Obsidian vault and refactoring code across multiple files.
Current State and Limitations
This is the first release, and I need to be upfront about its limitations. I’m not a security expert and I’m relatively new to Go development. While sqd works well for basic text operations, it has several security issues that need to be addressed before it should be used in production environments:
- No input sanitization: SQL-like queries aren’t fully validated
- Non-atomic operations: UPDATE and DELETE aren’t transactional, files can get corrupted if something goes wrong
- Silent error handling: Many errors are ignored instead of reported
- Race conditions: Multiple concurrent sqd processes can interfere with each other
I’ve opened an issue tracking these problems and what needs to be fixed: https://github.com/albertoboccolini/sqd/issues/5
Future developments
Right now sqd only works with file content through the content property. To make the tool more flexible and treat files more like database tables,
I want to add additional properties that act like columns you can query and filter on. Planned properties:
- filename (#1): Query by file name or display only filenames in results. This would let you search content but show only which files match, or search by filename patterns instead of content.
- path (#2): Work with full file paths to distinguish files with the same name in different directories. Useful for filtering by location or finding files in specific subdirectories.
- extension (#3): Filter by file type more explicitly than glob patterns. This makes it easier to search across multiple file types or exclude certain extensions.
- line (#4): Filter by line number to work with specific sections of files. You could search only in file headers, process specific line ranges, or count matches in different parts of files.
Beyond property additions, I also want to introduce safety mechanisms for destructive operations (#6). Currently UPDATE and DELETE directly overwrite files without backups or rollback capabilities. Adding atomic operations, automatic backups, and a dry-run mode would make sqd much safer for production use.
How You Can Help
If you’re an experienced Go developer, security-focused programmer, or just someone who likes the idea and wants to contribute, I’d appreciate your help. You can:
- Fix security issues and submit pull requests
- Review the codebase and suggest improvements
- Test the tool and report bugs
- Share feedback on what features would make it more useful
The goal is to keep sqd simple and maintainable while making it safe enough for real-world use.
Get Started
You can find sqd on GitHub: https://github.com/albertoboccolini/sqd
Installation is straightforward if you have Go installed:
go install github.com/albertoboccolini/sqd@latestOr download pre-built binaries from the releases page.
I’m open to all feedback on what would make this tool more useful. Whether you want to contribute code, report issues, or just share your thoughts on the concept, I’d love to hear from you.