Commit 1563958e authored by Jacob Schatz's avatar Jacob Schatz

add sql formatter

parent dbdd2b26
......@@ -117,15 +117,6 @@ def get_sql(model_name, explore_name):
order_by = '{} DESC'.format(order_by)
table = sqlHelper.table(base_table, explore_name)
fields = sqlHelper.fields(incoming_dimensions, explore_name)
q = Query\
.from_(table)\
.select(*fields, explore_name)
print(str(q))
base_sql = 'SELECT\n\t{}\nFROM {} AS {} \n{} {} \n{} \n{} \nLIMIT {};'.format(',\n '.join(to_join), base_table, explore_name, filter_by, join_sql, group_by, order_by, limit);
if to_run:
db_to_connect = model.settings['connection']
......
......@@ -21,6 +21,7 @@
"axios": "^0.18.0",
"bulma": "^0.7.1",
"chart.js": "^2.7.2",
"sql-formatter": "^2.3.1",
"ssf": "^0.10.2",
"vue": "^2.5.2",
"vue-router": "^3.0.1",
......
......@@ -275,7 +275,7 @@
<ResultTable></ResultTable>
<div>
<div class="" v-if="isSQLTab && currentSQL">
<code>{{currentSQL}}</code>
<code>{{formattedSql}}</code>
</div>
</div>
</template>
......@@ -342,6 +342,7 @@ export default {
'hasJoins',
'getLabelForJoin',
'showJoinDimensionMeasureHeader',
'formattedSql',
]),
limit: {
......
import SSF from 'ssf';
import Vue from 'vue';
import sqlFormatter from 'sql-formatter';
import exploreApi from '../../api/explore';
import utils from '../../api/utils';
......@@ -113,6 +114,10 @@ const getters = {
currentLimit() {
return state.limit;
},
formattedSql() {
return sqlFormatter.format(state.currentSQL);
},
};
const actions = {
......
......@@ -4980,7 +4980,7 @@ lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
lodash@4.x, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.3.0, lodash@~4.17.10:
lodash@4.x, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.16.0, lodash@^4.17.10, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.3.0, lodash@~4.17.10:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
......@@ -7326,6 +7326,13 @@ sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
sql-formatter@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/sql-formatter/-/sql-formatter-2.3.1.tgz#5e346703a620302eea5375211e8f08cb670e8222"
dependencies:
babel-runtime "^6.18.0"
lodash "^4.16.0"
ssf@^0.10.2:
version "0.10.2"
resolved "https://registry.yarnpkg.com/ssf/-/ssf-0.10.2.tgz#65b2b4fcdfd967bc8e8383a41349009893115976"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment