condition building
This commit is contained in:
parent
1f8349f8d0
commit
ff253c73f0
9 changed files with 112 additions and 19 deletions
|
@ -29,6 +29,13 @@
|
||||||
>
|
>
|
||||||
<NoSymbolIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
<NoSymbolIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
class="p-1 border border-gray-400 bg-red-200 rounded-md"
|
||||||
|
title="Anfrage löschen"
|
||||||
|
@click="$emit('update:model-value', undefined)"
|
||||||
|
>
|
||||||
|
<TrashIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-2 h-44 md:h-60 w-full overflow-y-scroll">
|
<div class="p-2 h-44 md:h-60 w-full overflow-y-scroll">
|
||||||
<Table v-model="value" />
|
<Table v-model="value" />
|
||||||
|
@ -40,7 +47,13 @@
|
||||||
import { defineComponent, type PropType } from "vue";
|
import { defineComponent, type PropType } from "vue";
|
||||||
import { mapActions, mapState } from "pinia";
|
import { mapActions, mapState } from "pinia";
|
||||||
import type { DynamicQueryStructure } from "../../types/dynamicQueries";
|
import type { DynamicQueryStructure } from "../../types/dynamicQueries";
|
||||||
import { ArchiveBoxArrowDownIcon, InboxArrowDownIcon, NoSymbolIcon, PlayIcon } from "@heroicons/vue/24/outline";
|
import {
|
||||||
|
ArchiveBoxArrowDownIcon,
|
||||||
|
InboxArrowDownIcon,
|
||||||
|
NoSymbolIcon,
|
||||||
|
PlayIcon,
|
||||||
|
TrashIcon,
|
||||||
|
} from "@heroicons/vue/24/outline";
|
||||||
import { useQueryBuilderStore } from "../../stores/admin/queryBuilder";
|
import { useQueryBuilderStore } from "../../stores/admin/queryBuilder";
|
||||||
import Table from "./Table.vue";
|
import Table from "./Table.vue";
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -8,10 +8,17 @@
|
||||||
</select>
|
</select>
|
||||||
<select v-model="column">
|
<select v-model="column">
|
||||||
<option value="" disabled>Verknüpfung auswählen</option>
|
<option value="" disabled>Verknüpfung auswählen</option>
|
||||||
<option v-for="col in activeTable?.columns" :value="col">
|
<option v-for="col in activeTable?.columns" :value="col.column">
|
||||||
{{ foreignColumns?.includes(col.column) ? "FK:" : "" }} {{ col.column }}:{{ col.type }}
|
{{ foreignColumns?.includes(col.column) ? "FK:" : "" }} {{ col.column }}:{{ col.type }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
<select v-model="operation" class="!w-fit !h-fit">
|
||||||
|
<option value="" disabled>Vergleich auswählen</option>
|
||||||
|
<option v-for="op in whereOperationArray" :value="op">
|
||||||
|
{{ op }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<input v-model="value" :type="inputType" />
|
||||||
<div class="p-1 border border-gray-400 hover:bg-gray-200 rounded-md" @click="$emit('remove')">
|
<div class="p-1 border border-gray-400 hover:bg-gray-200 rounded-md" @click="$emit('remove')">
|
||||||
<TrashIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
<TrashIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,7 +28,13 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineComponent, type PropType } from "vue";
|
import { defineComponent, type PropType } from "vue";
|
||||||
import { mapActions, mapState } from "pinia";
|
import { mapActions, mapState } from "pinia";
|
||||||
import type { ConditionStructure, ConditionValue, WhereOperation, WhereType } from "../../types/dynamicQueries";
|
import {
|
||||||
|
whereOperationArray,
|
||||||
|
type ConditionStructure,
|
||||||
|
type ConditionValue,
|
||||||
|
type WhereOperation,
|
||||||
|
type WhereType,
|
||||||
|
} from "../../types/dynamicQueries";
|
||||||
import { useQueryBuilderStore } from "../../stores/admin/queryBuilder";
|
import { useQueryBuilderStore } from "../../stores/admin/queryBuilder";
|
||||||
import { TrashIcon } from "@heroicons/vue/24/outline";
|
import { TrashIcon } from "@heroicons/vue/24/outline";
|
||||||
</script>
|
</script>
|
||||||
|
@ -50,6 +63,20 @@ export default defineComponent({
|
||||||
foreignColumns() {
|
foreignColumns() {
|
||||||
return this.activeTable?.relations.map((r) => r.column);
|
return this.activeTable?.relations.map((r) => r.column);
|
||||||
},
|
},
|
||||||
|
inputType() {
|
||||||
|
let type = this.activeTable?.columns.find((c) => c.column == this.column)?.type;
|
||||||
|
if (this.operation.includes("timespan")) return "number";
|
||||||
|
switch (type) {
|
||||||
|
case "int":
|
||||||
|
return "number";
|
||||||
|
case "varchar":
|
||||||
|
return "text";
|
||||||
|
case "date":
|
||||||
|
return "date";
|
||||||
|
default:
|
||||||
|
return "text";
|
||||||
|
}
|
||||||
|
},
|
||||||
concat: {
|
concat: {
|
||||||
get() {
|
get() {
|
||||||
return this.modelValue.concat;
|
return this.modelValue.concat;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-row gap-2 w-full border border-gray-300 rounded-md p-1">
|
<div class="flex flex-row gap-2 w-full border border-gray-300 rounded-md p-1">
|
||||||
<select v-model="concat" class="!w-20 !h-fit">
|
<select v-if="concat != '_'" v-model="concat" class="!w-20 !h-fit">
|
||||||
<option value="" disabled>Verknüpfung auswählen</option>
|
<option value="" disabled>Verknüpfung auswählen</option>
|
||||||
<option v-for="operation in ['AND', 'OR']" :value="operation">
|
<option v-for="operation in ['AND', 'OR']" :value="operation">
|
||||||
{{ operation }}
|
{{ operation }}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<Condition
|
<Condition
|
||||||
v-else
|
v-else
|
||||||
:model-value="condition"
|
:model-value="condition"
|
||||||
|
:table="table"
|
||||||
@update:model-value="($event) => (value[index] = $event)"
|
@update:model-value="($event) => (value[index] = $event)"
|
||||||
@remove="removeAtIndex(index)"
|
@remove="removeAtIndex(index)"
|
||||||
/>
|
/>
|
||||||
|
@ -72,7 +73,7 @@ export default defineComponent({
|
||||||
addNestedToValue() {
|
addNestedToValue() {
|
||||||
this.value.push({
|
this.value.push({
|
||||||
structureType: "nested",
|
structureType: "nested",
|
||||||
concat: "AND",
|
concat: this.value.length == 0 ? "_" : "AND",
|
||||||
conditions: [],
|
conditions: [],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<TableSelect v-model="table" />
|
<TableSelect v-model="table" />
|
||||||
<ColumnSelect v-model="columnSelect" :table="table" />
|
<ColumnSelect v-if="table != ''" v-model="columnSelect" :table="table" />
|
||||||
<Where v-model="where" :table="table" />
|
<Where v-if="table != ''" v-model="where" :table="table" />
|
||||||
<Order v-model="order" :table="table" :columns="columnSelect" />
|
<Order v-if="table != ''" v-model="order" :table="table" :columns="columnSelect" />
|
||||||
<Join v-model="modelValue.join" :table="table" />
|
<Join v-if="table != ''" v-model="modelValue.join" :table="table" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ export default defineComponent({
|
||||||
addNestedToValue() {
|
addNestedToValue() {
|
||||||
this.value.push({
|
this.value.push({
|
||||||
structureType: "nested",
|
structureType: "nested",
|
||||||
concat: "AND",
|
concat: this.value.length == 0 ? "_" : "AND",
|
||||||
conditions: [],
|
conditions: [],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import type { CreateAwardViewModel, UpdateAwardViewModel, AwardViewModel } from "@/viewmodels/admin/award.models";
|
|
||||||
import { http } from "@/serverCom";
|
import { http } from "@/serverCom";
|
||||||
import type { AxiosResponse } from "axios";
|
|
||||||
import type { TableMeta } from "../../viewmodels/admin/query.models";
|
import type { TableMeta } from "../../viewmodels/admin/query.models";
|
||||||
import type { DynamicQueryStructure } from "../../types/dynamicQueries";
|
import type { DynamicQueryStructure } from "../../types/dynamicQueries";
|
||||||
|
|
||||||
|
@ -12,7 +10,8 @@ export const useQueryBuilderStore = defineStore("queryBuilder", {
|
||||||
loading: "loading" as "loading" | "fetched" | "failed",
|
loading: "loading" as "loading" | "fetched" | "failed",
|
||||||
data: [] as Array<{ id: number; [key: string]: any }>,
|
data: [] as Array<{ id: number; [key: string]: any }>,
|
||||||
totalLength: 0 as number,
|
totalLength: 0 as number,
|
||||||
loadingData: "failed" as "loading" | "fetched" | "failed",
|
loadingData: "fetched" as "loading" | "fetched" | "failed",
|
||||||
|
queryError: "" as string | { sql: string; code: string; msg: string },
|
||||||
query: undefined as undefined | DynamicQueryStructure,
|
query: undefined as undefined | DynamicQueryStructure,
|
||||||
isLoadedQuery: undefined as undefined | number,
|
isLoadedQuery: undefined as undefined | number,
|
||||||
};
|
};
|
||||||
|
@ -38,17 +37,25 @@ export const useQueryBuilderStore = defineStore("queryBuilder", {
|
||||||
query: this.query,
|
query: this.query,
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
this.data = result.data.rows;
|
if (result.data.stats == "success") {
|
||||||
this.totalLength = result.data.total;
|
this.data = result.data.rows;
|
||||||
this.loadingData = "fetched";
|
this.totalLength = result.data.total;
|
||||||
|
this.loadingData = "fetched";
|
||||||
|
} else {
|
||||||
|
this.queryError = result.data ?? "An error occurred";
|
||||||
|
this.loadingData = "failed";
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
this.queryError = "An error occurred";
|
||||||
this.loadingData = "failed";
|
this.loadingData = "failed";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
clearResults() {
|
clearResults() {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
this.totalLength = 0;
|
this.totalLength = 0;
|
||||||
|
this.queryError = "";
|
||||||
|
this.loadingData = "fetched";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,7 +43,8 @@ export type WhereOperation =
|
||||||
| "notNull" // Is not null
|
| "notNull" // Is not null
|
||||||
| "between" // Is between
|
| "between" // Is between
|
||||||
| "startsWith" // Starts with
|
| "startsWith" // Starts with
|
||||||
| "endsWith"; // Ends with
|
| "endsWith" // Ends with
|
||||||
|
| "timespanEq"; // Date before x years (YYYY-01-01 <bis> YYYY-12-31)
|
||||||
// TODO: age between | age equals | age greater | age smaller
|
// TODO: age between | age equals | age greater | age smaller
|
||||||
|
|
||||||
export type OrderByStructure = {
|
export type OrderByStructure = {
|
||||||
|
@ -52,3 +53,22 @@ export type OrderByStructure = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OrderByType = "ASC" | "DESC";
|
export type OrderByType = "ASC" | "DESC";
|
||||||
|
|
||||||
|
export const whereOperationArray = [
|
||||||
|
"eq",
|
||||||
|
"neq",
|
||||||
|
"lt",
|
||||||
|
"lte",
|
||||||
|
"gt",
|
||||||
|
"gte",
|
||||||
|
"in",
|
||||||
|
"notIn",
|
||||||
|
"contains",
|
||||||
|
"notContains",
|
||||||
|
"null",
|
||||||
|
"notNull",
|
||||||
|
"between",
|
||||||
|
"startsWith",
|
||||||
|
"endsWith",
|
||||||
|
"timespanEq",
|
||||||
|
];
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #diffMain>
|
<template #diffMain>
|
||||||
<div class="flex flex-col w-full h-full gap-2 justify-center px-7">
|
<div class="flex flex-col w-full h-full gap-2 px-7 overflow-y-auto">
|
||||||
<BuilderHost
|
<BuilderHost
|
||||||
v-model="query"
|
v-model="query"
|
||||||
@query:run="sendQuery()"
|
@query:run="sendQuery()"
|
||||||
|
@ -15,7 +15,32 @@
|
||||||
@results:export=""
|
@results:export=""
|
||||||
/>
|
/>
|
||||||
<p>Ergebnisse:</p>
|
<p>Ergebnisse:</p>
|
||||||
|
<div
|
||||||
|
v-if="loadingData == 'failed'"
|
||||||
|
class="flex flex-col p-2 border border-red-600 bg-red-200 rounded-md select-none"
|
||||||
|
>
|
||||||
|
<p v-if="typeof queryError == 'string'">
|
||||||
|
{{ queryError }}
|
||||||
|
</p>
|
||||||
|
<div v-else>
|
||||||
|
<p>
|
||||||
|
CODE: <br />
|
||||||
|
{{ queryError.code }}
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<p>
|
||||||
|
MSG: <br />
|
||||||
|
{{ queryError.msg }}
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<p>
|
||||||
|
RESULTING SQL: <br />
|
||||||
|
{{ queryError.sql }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<Pagination
|
<Pagination
|
||||||
|
v-else
|
||||||
:items="data"
|
:items="data"
|
||||||
:totalCount="totalLength"
|
:totalCount="totalLength"
|
||||||
:indicateLoading="loadingData == 'loading'"
|
:indicateLoading="loadingData == 'loading'"
|
||||||
|
@ -43,7 +68,7 @@ import type { DynamicQueryStructure } from "@/types/dynamicQueries";
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useQueryBuilderStore, ["loading", "loadingData", "tableMetas", "data", "totalLength"]),
|
...mapState(useQueryBuilderStore, ["loading", "loadingData", "tableMetas", "data", "totalLength", "queryError"]),
|
||||||
...mapWritableState(useQueryBuilderStore, ["query"]),
|
...mapWritableState(useQueryBuilderStore, ["query"]),
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
Loading…
Reference in a new issue