joereynolds / SQHell.vim

An SQL wrapper for vim
MIT License
131 stars 9 forks source link

Extract SQL querys to seperate functions to enable easy reload of buffer contents on change #46

Open jbyte opened 6 years ago

jbyte commented 6 years ago

As implied in this comment I think it would be a good idea to extract all SQL query generations (even if really simple) to their own functions which would enable a very easy and simple reload functionality for SQHDatabase, SQHTable, and SQHResult buffers when using key bindings that change their contents.

Currently reloading is done like this: open SQHDatabase -> dd to delete a database -> mysql#DropDatabase(which creates the query, executes the query with mysql#GetResultsFromQuery, deletes the buffer, and opens new buffer with mysql#ShowDatabases)

My idea is to make it work like this: open SQHDatabase -> dd to delete a database -> mysql#DropDatabase(which creates the query, executes the query, deletes all the lines in the current buffer, gets query for showing all the databases, and executes that query with mysql#GetResultsFromQuery) Note: the empty buffer and fill with new contents would be a separate function

Pros:

Cons:

joereynolds commented 6 years ago

Sounds good to me, we can test the query generation better this way too.

Do we need to delete all lines in the buffer each time? We use enew! inside the InsertResultsToNewBuffer function anyway so the previous buffer would be removed (though still available in the jump list I guess).

Also it sounds like the pros outweight the cons so feel free to take a stab it, I would definitely like a cleaner codebase for this

jbyte commented 6 years ago

I'll get started some time later today/tomorrow. The reason for deleting lines is mostly to use keepjumps so the jump list doesn't get modified. But I'll look into just modifying the buffer instead of delete and put. Maybe with the help of diff?