sasha-alias / sqltabs

Rich SQL client for Postgresql, MySQL, MS SQL, Amazon Redshift, Google Firebase (Firestore)
https://www.sqltabs.com
GNU General Public License v3.0
803 stars 57 forks source link

Multiple markdown directives - only the first one works #97

Open MikeDBR opened 7 years ago

MikeDBR commented 7 years ago

Great work on sqltabs. At first look I didn't get it, but PgAdmin sucks, and it forced me to look again, and discover the gems within. I particularly like the vim mode, as most query tools are quite lacking in editing features.

Here are my queries... It only generates the first markdown, not others.

/**
## Count of all_my_patients
**/
select count(*) from all_my_patients
where user_account_id=102;

/**
## All My Patients
**/
select * from all_my_patients
where user_account_id=102;

I would like to be able to output markdown before each query - is this possible?

sasha-alias commented 7 years ago

Hi, thank you for a feedback. Yes it is possible to generate several markdowns. For that you need to split your script to so called SQL blocks. The block is a part of script between two lines starting with 3 dashes. Markdown is detected in the beginning and the end of each block, so you can split your script to several blocks and add markdown to a header and footer of a block:

/** 
## Plain dataset example
**/
select chr(n), random() from generate_series(1, 10) n;

/**
***
**/
--- chart bubble
/** 
## Bubble chart example
**/
select chr(n), random() from generate_series(1, 10) n

http://www.sqltabs.com/api/1.0/docs/369d90efe46194bfa378b1732e835a01?echo=true

In your particular case it will be:

/**
## Count of all_my_patients
**/
select count(*) from all_my_patients
where user_account_id=102;

---
/**
## All My Patients
**/
select * from all_my_patients
where user_account_id=102;
mikkelking commented 7 years ago

I can't get it to work reliably, even the example you provided for my queries doesn't work. In this example: http://www.sqltabs.com/api/1.0/docs/83b22d4f21afaf2df4dc698f56fd7244?echo=true Footer 1 and the next query don't appear, but Footer 2 does

sasha-alias commented 7 years ago

I think I know where is the issue. Most probably you execute your script with CMD+R Run Script. This type of query execution doesn't try to interpret blocks. Try to execute it with CMD+Shift+E Execute All Blocks

mikkelking commented 7 years ago

Right, at last a way to make it work, which is good, thanks!

Although, even if I select everything and type CMD+R then the output is different. It would be good from my perspective for it all to work the same way, as I am usually editing a larger script and will select a part of it to run each time.

Cheers

Mike