mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
5.7 KiB
222 lines
5.7 KiB
3 years ago
|
export const state = () => ({
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* type : SELECT, INSERT, UPDATE, CREATE, DELETE, DROP
|
||
|
*
|
||
|
* query :
|
||
|
*
|
||
|
*
|
||
|
* response :
|
||
|
* status : 0 / -1
|
||
|
*
|
||
|
*/
|
||
|
list: [{
|
||
|
type: 'SELECT',
|
||
|
query: 'SELECT 1',
|
||
3 years ago
|
response: { status: 0 }
|
||
3 years ago
|
}],
|
||
|
clipboardQuery: null,
|
||
|
// editors: ['', '', '']
|
||
|
editors: [
|
||
|
{
|
||
|
type: 'temp',
|
||
|
code: '',
|
||
|
fileName: null,
|
||
|
filePath: null,
|
||
|
edited: false
|
||
|
}, {
|
||
|
type: 'temp',
|
||
|
code: '',
|
||
|
fileName: null,
|
||
|
filePath: null,
|
||
|
edited: false
|
||
|
}, {
|
||
|
type: 'temp',
|
||
|
code: '',
|
||
|
fileName: null,
|
||
|
filePath: null,
|
||
|
edited: false
|
||
3 years ago
|
}
|
||
3 years ago
|
],
|
||
|
|
||
|
sqlFilePaths: [],
|
||
|
|
||
|
projectSqlFilePaths: {},
|
||
|
currentProjectKey: ''
|
||
|
|
||
3 years ago
|
})
|
||
3 years ago
|
|
||
|
export const mutations = {
|
||
|
|
||
3 years ago
|
MutSqlFilePathsAdd(state, args) {
|
||
3 years ago
|
state.projectSqlFilePaths = {
|
||
|
...state.projectSqlFilePaths,
|
||
|
[state.currentProjectKey]: [...state.projectSqlFilePaths[state.currentProjectKey], args]
|
||
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
MutSqlFilePathsRemove(state, index) {
|
||
3 years ago
|
state.projectSqlFilePaths[state.currentProjectKey].splice(index, 1)
|
||
|
state.projectSqlFilePaths[state.currentProjectKey] = [...state.projectSqlFilePaths[state.currentProjectKey]]
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
MutList(state, list) {
|
||
3 years ago
|
state.projectSqlFilePaths[state.currentProjectKey] = list
|
||
3 years ago
|
},
|
||
3 years ago
|
MutCurrentProjectKey(state, currentProjectKey) {
|
||
3 years ago
|
state.currentProjectKey = currentProjectKey
|
||
3 years ago
|
},
|
||
3 years ago
|
MutListAdd(state, args) {
|
||
3 years ago
|
state.list.unshift(args)
|
||
|
if (state.list.length > 500) { state.list.pop() }
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
MutListRemove(state, index) {
|
||
3 years ago
|
// find index and set status
|
||
3 years ago
|
state.list.splice(index, 1)
|
||
3 years ago
|
state.list = [...state.list]
|
||
|
},
|
||
3 years ago
|
MutListRemoveItem(state, item) {
|
||
3 years ago
|
state.list = state.list.filter(query => item.query !== query.query)
|
||
|
},
|
||
3 years ago
|
MutSetClipboardQuery(state, clipboardQuery) {
|
||
3 years ago
|
state.clipboardQuery = clipboardQuery
|
||
3 years ago
|
},
|
||
3 years ago
|
MutSetEditorByIndex(state, { editor, index }) {
|
||
3 years ago
|
state.editors[index] = editor
|
||
|
state.editors = [...state.editors]
|
||
3 years ago
|
},
|
||
3 years ago
|
MutSetEditors(state, editors) {
|
||
3 years ago
|
state.editors = editors.map(editor => ({ ...editor }))
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
export const getters = {
|
||
3 years ago
|
GtrCurrentSqlFilePaths(state) {
|
||
3 years ago
|
return state.projectSqlFilePaths[state.currentProjectKey]
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
export const actions = {
|
||
|
|
||
3 years ago
|
async executeQuery({ commit, state, rootState }, { envs, query }) {
|
||
3 years ago
|
// const sqlMgr = rootState.sqlMgr.sqlMgr
|
||
|
let result
|
||
3 years ago
|
// const type = SqlQueryParser.getType(query);
|
||
|
// const typeColor = SqlQueryParser.getColorForQueryType(type)
|
||
|
|
||
|
// let t = process.hrtime();
|
||
3 years ago
|
// eslint-disable-next-line no-useless-catch
|
||
3 years ago
|
try {
|
||
|
// const client = await sqlMgr.projectGetSqlClient(envs);
|
||
|
|
||
|
// result = await sqlMgr.sqlOp(envs, 'executeRawQuery', query);
|
||
3 years ago
|
result = await this.dispatch('sqlMgr/ActSqlOp', [envs, 'executeRawQuery', query])
|
||
3 years ago
|
|
||
|
// var t1 = process.hrtime(t);
|
||
|
// var t2 = (t1[0] + t1[1] / 1000000000).toFixed(2);
|
||
|
|
||
|
// commit('MutListAdd', {
|
||
|
// id: Date.now(),
|
||
|
// name: '',
|
||
|
// query: query,
|
||
|
// type,
|
||
|
// typeColor,
|
||
|
// response: {status: 0},
|
||
|
// createdAt: Date.now(),
|
||
|
// timeTaken: t2,
|
||
|
// })
|
||
|
} catch (e) {
|
||
|
// var t1 = process.hrtime(t);
|
||
|
// var t2 = (t1[0] + t1[1] / 1000000000).toFixed(2);
|
||
|
//
|
||
|
// commit('MutListAdd', {
|
||
|
// id: Date.now(),
|
||
|
// name: '',
|
||
|
// query: query,
|
||
|
// type,
|
||
|
// typeColor,
|
||
|
// response: {status: -1},
|
||
|
// createdAt: Date.now(),
|
||
|
// timeTaken: t2,
|
||
|
//
|
||
|
// });
|
||
3 years ago
|
throw e
|
||
3 years ago
|
}
|
||
3 years ago
|
return result
|
||
3 years ago
|
|
||
|
//
|
||
|
//
|
||
|
// let a = {...action};
|
||
|
// try {
|
||
|
// commit('notification/MutToggleProgressBar', true, {root: true});
|
||
|
//
|
||
|
// if(action.body) {
|
||
|
// try {
|
||
|
// a.body = JSON.parse(a.body);
|
||
|
// } catch (e) {
|
||
|
// console.log(e);
|
||
|
// }
|
||
|
// }
|
||
|
// if(action.headers) {
|
||
|
// try {
|
||
|
// a.headers = JSON.parse(a.headers);
|
||
|
// } catch (e) {
|
||
|
// console.log(e);
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// a.response = {};
|
||
|
// let data = await axios({
|
||
|
// url: a.url,
|
||
|
// method: a.type,
|
||
|
// data: a.body,
|
||
|
// headers: a.headers
|
||
|
// });
|
||
|
//
|
||
|
// a.response.status = data.status;
|
||
|
// a.response.data = data.data;
|
||
|
// console.log(data);
|
||
|
// } catch (e) {
|
||
|
// console.log(Object.keys(e), Object.entries(e));
|
||
|
// a.response = e.response;
|
||
|
// //throw e;
|
||
|
// } finally {
|
||
|
// commit('notification/MutToggleProgressBar', false, {root: true});
|
||
|
// commit('MutListAdd', {...a,body:JSON.stringify(a.body),headers:JSON.stringify(a.headers)});
|
||
|
// return a.response;
|
||
|
// }
|
||
|
},
|
||
3 years ago
|
async loadSqlCollectionForProject({ commit, state }, { projectName, projectId }) {
|
||
3 years ago
|
const key = projectName + '__' + projectId
|
||
3 years ago
|
commit('MutCurrentProjectKey', key)
|
||
|
if (!(key in state.projectSqlFilePaths)) {
|
||
3 years ago
|
commit('MutList', [])
|
||
3 years ago
|
}
|
||
|
}
|
||
3 years ago
|
}
|
||
3 years ago
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|