Collaborative SQL Editor
Write SQL queries together in real time with shared cursors, and validate, format or minify them for everyone.
Readme
What is collaborative SQL editing?
Collaborative SQL editing lets several people write and review queries at the same time, each in their own browser. It is handy for working out a query with a colleague, reviewing a migration together, or teaching SQL, without screen sharing or pasting queries into chat.
To keep everyone's copy identical, changes travel as small edits rather than the whole text, and one server decides the order they apply in. Edits made at the same moment are adjusted to each other, so both survive.
Tool description
This tool is a shared SQL editor with syntax highlighting. Open it and send the link: everyone in the room edits the same queries in real time, sees each other's cursors, and can validate, format or minify the SQL for everyone with one click.
Validation parses the SQL with node-sql-parser. Formatting puts each major clause (SELECT, FROM, WHERE, JOIN and so on) on its own line without touching strings and comments, and minifying puts the query on one line. The new text replaces only the lines that changed, so what others type in the meantime stays where it is.
Features
- Real-time editing - changes from everyone appear instantly and are merged when people type at the same moment
- Cursors and selections - see where each person is, in the color shown next to their name
- Validate - checks that the SQL parses, and shows the parser's message when it doesn't
- Format and minify - lay out the query clause by clause, or squeeze it onto one line, for everyone in the room
- Copy and download - keep a copy of the queries as a .sql file
How it works
When the page opens, it creates a room on the sync server and puts its link in the address bar. Everyone who opens the link joins the same room and sees the same document.
Every change is sent to the server as a small description of what changed - which characters were inserted or deleted where - instead of the whole text. The server puts changes from everyone in a single order, moves a change that was made on top of an older version past the ones that came first, and passes the result on to everyone else. Your own typing shows up right away, and changes from others are merged around it, so nobody's typing gets lost when two people edit at the same moment.
The document is kept in the server's memory only while the room is open. If you reload the page, you get back into the room with the text as it was; once everyone has left, the room and its text are gone.
Limitations
- A room holds up to 20 people and 100,000 characters.
- Nothing is stored after a room closes. Download the text before the last person leaves.
- Very fast or very large changes, such as pasting the whole document many times in a row, are refused and the editor reloads the room's text.
- Opening a room link in another of the collaborative editors (for example a SQL room in the JavaScript editor) shows "Room not found": each room belongs to one language.
- Validation checks syntax only. Queries are never run against a database.