Skip to content

Commit

Permalink
Resolve mix query method.
Browse files Browse the repository at this point in the history
  • Loading branch information
caioricciuti committed May 25, 2024
1 parent 1e13d7b commit df9f423
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,38 @@ jobs:
echo "New tag: $new_tag"
echo "new_tag=$new_tag" >> $GITHUB_ENV
- name: Check if tag exists
id: tag_check
run: |
set -e # Fail on first error
if git rev-parse "refs/tags/${{ env.new_tag }}" >/dev/null 2>&1; then
echo "Tag already exists."
# Increment the minor version instead
new_minor=$((minor + 1))
new_patch=0
new_tag="v$major.$new_minor.$new_patch"
echo "New incremented tag: $new_tag"
echo "new_tag=$new_tag" >> $GITHUB_ENV
else
echo "Tag does not exist."
echo "new_tag=$new_tag" >> $GITHUB_ENV
- name: Create new tag
run: |
set -e # Fail on first error
git tag ${{ env.new_tag }}
git push origin ${{ env.new_tag }}
- name: Create GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GHCR_PAT }}
with:
tag_name: ${{ env.new_tag }}
release_name: ${{ env.new_tag }}
body: "Automated release for tag ${{ env.new_tag }}"
draft: false
prerelease: false
32 changes: 23 additions & 9 deletions src/providers/TabsStateContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const TabsStateProvider = ({ children }) => {

const runQuery = async (tabId, query) => {
setIsLoadingQuery(true);

// Timeout function
const timeout = (ms) =>
new Promise((_, reject) =>
Expand All @@ -173,18 +174,31 @@ export const TabsStateProvider = ({ children }) => {
return;
}

// if query has create or insert statements, show a warning
const isCreateOrInsert =
query.toLowerCase().includes("create") ||
query.toLowerCase().includes("insert") ||
query.toLowerCase().includes("alter") ||
query.toLowerCase().includes("drop");
// Function to check if the query is a create or insert statement
const isCreateOrInsert = (query) => {
const lowerQuery = query.toLowerCase();
const createTableRegex = /\bcreate\s+table\b/;
const insertRegex = /\binsert\b/;
const alterRegex = /\balter\b/;
const dropTableRegex = /\bdrop\s+table\b/;
const dropColumnRegex = /\bdrop\s+column\b/;
const dropIndexRegex = /\bdrop\s+index\b/;

return (
createTableRegex.test(lowerQuery) ||
insertRegex.test(lowerQuery) ||
alterRegex.test(lowerQuery) ||
dropTableRegex.test(lowerQuery) ||
dropColumnRegex.test(lowerQuery) ||
dropIndexRegex.test(lowerQuery)
);
};

let result;
let data;

// Use Promise.race to set a timeout for the query execution
if (isCreateOrInsert) {
if (isCreateOrInsert(query)) {
result = await Promise.race([
clickHouseClient.current.command({
query,
Expand All @@ -210,15 +224,15 @@ export const TabsStateProvider = ({ children }) => {
// If the result is successful before timeout
updateQueryTab(tabId, {
last_run: new Date().toISOString(),
tab_results: isCreateOrInsert
tab_results: isCreateOrInsert(query)
? [
{
success: "true",
message: JSON.stringify(data),
},
]
: data.data,
tab_results_statistics: isCreateOrInsert ? [] : data.statistics,
tab_results_statistics: isCreateOrInsert(query) ? [] : data.statistics,
tab_errors: null,
});
} catch (error) {
Expand Down

0 comments on commit df9f423

Please sign in to comment.