Compare commits
No commits in common. "8087108b908ec9c7c6e7f743d9c1ca251024b83b" and "d018f972742fd92fde9a2b8e1855cfc89f3ccb44" have entirely different histories.
8087108b90
...
d018f97274
7 changed files with 59 additions and 181 deletions
|
@ -68,9 +68,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-2 h-60 md:h-60 w-full overflow-y-auto">
|
<div class="p-2 h-44 md:h-60 w-full overflow-y-auto">
|
||||||
<textarea v-if="typeof value == 'string'" v-model="value" placeholder="SQL Query" class="h-full w-full" />
|
<textarea v-if="typeof value == 'string'" v-model="value" placeholder="SQL Query" class="h-full w-full" />
|
||||||
<Table v-else v-model="value" enableOrder />
|
<Table v-else v-model="value" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineAsyncComponent, defineComponent, markRaw, type PropType } from "vue";
|
import { defineAsyncComponent, defineComponent, markRaw, type PropType } from "vue";
|
||||||
import { mapActions, mapState, mapWritableState } from "pinia";
|
import { mapActions, mapState, mapWritableState } from "pinia";
|
||||||
import { type DynamicQueryStructure } from "@/types/dynamicQueries";
|
import type { DynamicQueryStructure } from "@/types/dynamicQueries";
|
||||||
import {
|
import {
|
||||||
ArchiveBoxArrowDownIcon,
|
ArchiveBoxArrowDownIcon,
|
||||||
CommandLineIcon,
|
CommandLineIcon,
|
||||||
|
@ -94,7 +94,6 @@ import { useModalStore } from "@/stores/modal";
|
||||||
import Table from "./Table.vue";
|
import Table from "./Table.vue";
|
||||||
import { useAbilityStore } from "@/stores/ability";
|
import { useAbilityStore } from "@/stores/ability";
|
||||||
import { useQueryStoreStore } from "@/stores/admin/configuration/queryStore";
|
import { useQueryStoreStore } from "@/stores/admin/configuration/queryStore";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
@ -103,7 +102,6 @@ export default defineComponent({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: [Object, String] as PropType<DynamicQueryStructure | string>,
|
type: [Object, String] as PropType<DynamicQueryStructure | string>,
|
||||||
default: {
|
default: {
|
||||||
id: uuid(),
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "",
|
table: "",
|
||||||
where: [],
|
where: [],
|
||||||
|
@ -165,7 +163,6 @@ export default defineComponent({
|
||||||
this.activeQueryId = undefined;
|
this.activeQueryId = undefined;
|
||||||
if (typeof this.value != "string") {
|
if (typeof this.value != "string") {
|
||||||
this.value = {
|
this.value = {
|
||||||
id: uuid(),
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "",
|
table: "",
|
||||||
where: [],
|
where: [],
|
||||||
|
@ -185,7 +182,6 @@ export default defineComponent({
|
||||||
this.activeQueryId = undefined;
|
this.activeQueryId = undefined;
|
||||||
if (this.queryMode == "builder") {
|
if (this.queryMode == "builder") {
|
||||||
this.value = {
|
this.value = {
|
||||||
id: uuid(),
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "",
|
table: "",
|
||||||
where: [],
|
where: [],
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
v-for="(join, index) in value"
|
v-for="(join, index) in value"
|
||||||
:model-value="join"
|
:model-value="join"
|
||||||
:table="table"
|
:table="table"
|
||||||
:alreadyJoined="alreadyJoined"
|
|
||||||
@update:model-value="($event) => (value[index] = $event)"
|
@update:model-value="($event) => (value[index] = $event)"
|
||||||
@remove="removeAtIndex(index)"
|
@remove="removeAtIndex(index)"
|
||||||
/>
|
/>
|
||||||
|
@ -22,11 +21,10 @@
|
||||||
<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 DynamicQueryStructure } from "@/types/dynamicQueries";
|
import type { DynamicQueryStructure } from "@/types/dynamicQueries";
|
||||||
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
||||||
import { PlusIcon } from "@heroicons/vue/24/outline";
|
import { PlusIcon } from "@heroicons/vue/24/outline";
|
||||||
import JoinTable from "./JoinTable.vue";
|
import JoinTable from "./JoinTable.vue";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
@ -40,14 +38,16 @@ export default defineComponent({
|
||||||
type: Array as PropType<Array<DynamicQueryStructure & { foreignColumn: string }>>,
|
type: Array as PropType<Array<DynamicQueryStructure & { foreignColumn: string }>>,
|
||||||
default: [],
|
default: [],
|
||||||
},
|
},
|
||||||
alreadyJoined: {
|
|
||||||
type: Array as PropType<Array<string>>,
|
|
||||||
default: [],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
emits: ["update:model-value"],
|
emits: ["update:model-value"],
|
||||||
|
data() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
||||||
|
activeTable() {
|
||||||
|
return this.tableMetas.find((tm) => tm.tableName == this.table);
|
||||||
|
},
|
||||||
value: {
|
value: {
|
||||||
get() {
|
get() {
|
||||||
return this.modelValue;
|
return this.modelValue;
|
||||||
|
@ -60,7 +60,6 @@ export default defineComponent({
|
||||||
methods: {
|
methods: {
|
||||||
addToValue() {
|
addToValue() {
|
||||||
this.value.push({
|
this.value.push({
|
||||||
id: uuid(),
|
|
||||||
select: "*",
|
select: "*",
|
||||||
table: "",
|
table: "",
|
||||||
where: [],
|
where: [],
|
||||||
|
|
|
@ -4,23 +4,8 @@
|
||||||
<div class="flex flex-col gap-2 w-full">
|
<div class="flex flex-col gap-2 w-full">
|
||||||
<select v-model="foreignColumn" class="w-full">
|
<select v-model="foreignColumn" class="w-full">
|
||||||
<option value="" disabled>Relation auswählen</option>
|
<option value="" disabled>Relation auswählen</option>
|
||||||
<option
|
<option v-for="relation in activeTable?.relations" :value="relation.column">
|
||||||
v-for="relation in activeTable?.relations"
|
|
||||||
:value="relation.column"
|
|
||||||
:disabled="
|
|
||||||
alreadyJoined.includes(joinTableName(relation.referencedTableName)) &&
|
|
||||||
joinTableName(relation.referencedTableName) != value.table
|
|
||||||
"
|
|
||||||
>
|
|
||||||
{{ relation.column }} -> {{ joinTableName(relation.referencedTableName) }}
|
{{ relation.column }} -> {{ joinTableName(relation.referencedTableName) }}
|
||||||
<span
|
|
||||||
v-if="
|
|
||||||
alreadyJoined.includes(joinTableName(relation.referencedTableName)) &&
|
|
||||||
joinTableName(relation.referencedTableName) != value.table
|
|
||||||
"
|
|
||||||
>
|
|
||||||
(Join auf dieser Ebene besteht schon)
|
|
||||||
</span>
|
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<Table v-model="value" disable-table-select />
|
<Table v-model="value" disable-table-select />
|
||||||
|
@ -35,7 +20,7 @@
|
||||||
<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 DynamicQueryStructure } from "@/types/dynamicQueries";
|
import type { DynamicQueryStructure } from "@/types/dynamicQueries";
|
||||||
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
||||||
import Table from "./Table.vue";
|
import Table from "./Table.vue";
|
||||||
import { TrashIcon } from "@heroicons/vue/24/outline";
|
import { TrashIcon } from "@heroicons/vue/24/outline";
|
||||||
|
@ -55,14 +40,20 @@ export default defineComponent({
|
||||||
foreignColumn: string;
|
foreignColumn: string;
|
||||||
}
|
}
|
||||||
>,
|
>,
|
||||||
required: true,
|
default: {
|
||||||
},
|
select: "*",
|
||||||
alreadyJoined: {
|
table: "",
|
||||||
type: Array as PropType<Array<string>>,
|
where: [],
|
||||||
default: [],
|
join: [],
|
||||||
|
orderBy: [],
|
||||||
|
foreignColumn: "",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: ["update:model-value", "remove"],
|
emits: ["update:model-value", "remove"],
|
||||||
|
data() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
||||||
activeTable() {
|
activeTable() {
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
<p class="w-14 min-w-14 pt-2">SORT</p>
|
<p class="w-14 min-w-14 pt-2">ORDER</p>
|
||||||
<div class="flex flex-row flex-wrap gap-2 items-center w-full">
|
<div class="flex flex-row flex-wrap gap-2 items-center w-full">
|
||||||
<OrderStructure
|
<OrderStructure
|
||||||
v-for="(order, index) in value"
|
v-for="(order, index) in value"
|
||||||
:model-value="order"
|
:model-value="order"
|
||||||
:table="table"
|
:table="table"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:alreadySorted="alreadySorted"
|
|
||||||
:notFirst="index != 0"
|
|
||||||
:notLast="index != value.length - 1"
|
|
||||||
@up="changeSort('up', index)"
|
|
||||||
@down="changeSort('down', index)"
|
|
||||||
@update:model-value="($event) => (value[index] = $event)"
|
@update:model-value="($event) => (value[index] = $event)"
|
||||||
@remove="removeAtIndex(index)"
|
@remove="removeAtIndex(index)"
|
||||||
/>
|
/>
|
||||||
|
@ -40,15 +35,9 @@ export default defineComponent({
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
// columns: {
|
|
||||||
// type: [Array, String] as PropType<"*" | Array<string>>,
|
|
||||||
// default: "*",
|
|
||||||
// },
|
|
||||||
columns: {
|
columns: {
|
||||||
type: Array as PropType<
|
type: [Array, String] as PropType<"*" | Array<string>>,
|
||||||
Array<{ table: string; id: string; depth: number; path: string[]; columns: "*" | string[] }>
|
default: "*",
|
||||||
>,
|
|
||||||
default: [],
|
|
||||||
},
|
},
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Array as PropType<Array<OrderByStructure>>,
|
type: Array as PropType<Array<OrderByStructure>>,
|
||||||
|
@ -61,9 +50,6 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
||||||
alreadySorted() {
|
|
||||||
return this.modelValue.map((m) => ({ id: m.id, col: m.column }));
|
|
||||||
},
|
|
||||||
value: {
|
value: {
|
||||||
get() {
|
get() {
|
||||||
return this.modelValue;
|
return this.modelValue;
|
||||||
|
@ -76,9 +62,6 @@ export default defineComponent({
|
||||||
methods: {
|
methods: {
|
||||||
addToValue() {
|
addToValue() {
|
||||||
this.value.push({
|
this.value.push({
|
||||||
id: "",
|
|
||||||
depth: 0,
|
|
||||||
table: "",
|
|
||||||
column: "",
|
column: "",
|
||||||
order: "ASC",
|
order: "ASC",
|
||||||
});
|
});
|
||||||
|
@ -86,12 +69,6 @@ export default defineComponent({
|
||||||
removeAtIndex(index: number) {
|
removeAtIndex(index: number) {
|
||||||
this.value.splice(index, 1);
|
this.value.splice(index, 1);
|
||||||
},
|
},
|
||||||
changeSort(dir: "up" | "down", index: number) {
|
|
||||||
const swapIndex = dir === "up" ? index - 1 : index + 1;
|
|
||||||
if (swapIndex >= 0 && swapIndex < this.value.length) {
|
|
||||||
[this.value[index], this.value[swapIndex]] = [this.value[swapIndex], this.value[index]];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,26 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-row gap-2 items-center w-full">
|
<div class="flex flex-row gap-2 items-center w-full">
|
||||||
<div class="flex flex-col min-w-fit">
|
|
||||||
<ChevronUpIcon v-if="notFirst" class="w-4 h-4 stroke-2 cursor-pointer" @click.prevent="$emit('up')" />
|
|
||||||
<ChevronDownIcon v-if="notLast" class="w-4 h-4 stroke-2 cursor-pointer" @click.prevent="$emit('down')" />
|
|
||||||
</div>
|
|
||||||
<select v-model="column" class="w-full">
|
<select v-model="column" class="w-full">
|
||||||
<option value="" disabled>Spalte auswählen</option>
|
<option value="" disabled>Spalte auswählen</option>
|
||||||
<option
|
<option v-for="column in selectableColumns" :value="column">
|
||||||
v-for="selectable in selectableColumns"
|
{{ column }}
|
||||||
:value="`${selectable.id}_${selectable.column}`"
|
|
||||||
:disabled="
|
|
||||||
alreadySorted.some((as) => as.id == selectable.id && as.col == selectable.column) &&
|
|
||||||
`${selectable.id}_${selectable.column}` != column
|
|
||||||
"
|
|
||||||
>
|
|
||||||
{{ [...selectable.path, selectable.table].join("-") }} -> {{ selectable.column }}
|
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<select v-model="order">
|
<select v-model="order">
|
||||||
<option value="" disabled>Sortierung auswählen</option>
|
<option value="" disabled>Sortierung auswählen</option>
|
||||||
<option v-for="order in orderable" :value="order.key">
|
<option v-for="order in ['ASC', 'DESC']" :value="order">
|
||||||
{{ order.val }}
|
{{ order }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<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')">
|
||||||
|
@ -34,102 +23,47 @@ import { defineComponent, type PropType } from "vue";
|
||||||
import { mapActions, mapState } from "pinia";
|
import { mapActions, mapState } from "pinia";
|
||||||
import type { OrderByStructure, OrderByType } from "@/types/dynamicQueries";
|
import type { OrderByStructure, OrderByType } from "@/types/dynamicQueries";
|
||||||
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
||||||
import { TrashIcon, ChevronDownIcon, ChevronUpIcon } from "@heroicons/vue/24/outline";
|
import { TrashIcon } from "@heroicons/vue/24/outline";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
notFirst: {
|
|
||||||
type: Boolean,
|
|
||||||
defailt: false,
|
|
||||||
},
|
|
||||||
notLast: {
|
|
||||||
type: Boolean,
|
|
||||||
defailt: false,
|
|
||||||
},
|
|
||||||
table: {
|
table: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
// columns: {
|
|
||||||
// type: [Array, String] as PropType<"*" | Array<string>>,
|
|
||||||
// default: "*",
|
|
||||||
// },
|
|
||||||
columns: {
|
columns: {
|
||||||
type: Array as PropType<
|
type: [Array, String] as PropType<"*" | Array<string>>,
|
||||||
Array<{ table: string; id: string; depth: number; path: string[]; columns: "*" | string[] }>
|
default: "*",
|
||||||
>,
|
|
||||||
default: [],
|
|
||||||
},
|
},
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Object as PropType<OrderByStructure>,
|
type: Object as PropType<OrderByStructure>,
|
||||||
default: {},
|
default: {},
|
||||||
},
|
},
|
||||||
alreadySorted: {
|
|
||||||
type: Array as PropType<Array<{ id: string; col: string }>>,
|
|
||||||
default: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
emits: ["update:model-value", "remove", "up", "down"],
|
|
||||||
watch: {
|
|
||||||
columns() {
|
|
||||||
if (!this.columns.some((c) => c.id == this.modelValue.id)) {
|
|
||||||
this.$emit("remove");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
emits: ["update:model-value", "remove"],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {};
|
||||||
orderable: [
|
|
||||||
{ key: "ASC", val: "Aufsteigend (ABC)" },
|
|
||||||
{ key: "DESC", val: "Absteigend (CBA)" },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
||||||
// selectableColumns() {
|
|
||||||
// if (this.columns == "*") {
|
|
||||||
// let meta = this.tableMetas.find((tm) => tm.tableName == this.table);
|
|
||||||
// if (!meta) return [];
|
|
||||||
// let relCols = meta.relations.map((r) => r.column);
|
|
||||||
// return meta.columns.map((c) => c.column).filter((c) => !relCols.includes(c));
|
|
||||||
// } else {
|
|
||||||
// return this.columns;
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
selectableColumns() {
|
selectableColumns() {
|
||||||
return this.columns.reduce(
|
if (this.columns == "*") {
|
||||||
(acc, curr) => {
|
let meta = this.tableMetas.find((tm) => tm.tableName == this.table);
|
||||||
if (curr.columns == "*") {
|
if (!meta) return [];
|
||||||
let meta = this.tableMetas.find((tm) => tm.tableName == this.table);
|
let relCols = meta.relations.map((r) => r.column);
|
||||||
if (meta) {
|
return meta.columns.map((c) => c.column).filter((c) => !relCols.includes(c));
|
||||||
let relCols = meta.relations.map((r) => r.column);
|
} else {
|
||||||
meta.columns
|
return this.columns;
|
||||||
.map((c) => c.column)
|
}
|
||||||
.filter((c) => !relCols.includes(c))
|
|
||||||
.forEach((c) =>
|
|
||||||
acc.push({ id: curr.id, depth: curr.depth, table: curr.table, column: c, path: curr.path })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
curr.columns.forEach((c) =>
|
|
||||||
acc.push({ id: curr.id, depth: curr.depth, table: curr.table, column: c, path: curr.path })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
[] as Array<{ id: string; depth: number; table: string; column: string; path: string[] }>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
column: {
|
column: {
|
||||||
get() {
|
get() {
|
||||||
return `${this.modelValue.id}_${this.modelValue.column}`;
|
return this.modelValue.column;
|
||||||
},
|
},
|
||||||
set(val: `${string}_${string}`) {
|
set(val: string) {
|
||||||
let col = this.selectableColumns.find((sc) => sc.id == val.split("_")[0] && sc.column == val.split("_")[1]);
|
this.$emit("update:model-value", { ...this.modelValue, column: val });
|
||||||
this.$emit("update:model-value", { ...this.modelValue, ...col });
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
order: {
|
order: {
|
||||||
|
|
|
@ -3,14 +3,16 @@
|
||||||
<TableSelect v-model="table" :disableTableSelect="disableTableSelect" />
|
<TableSelect v-model="table" :disableTableSelect="disableTableSelect" />
|
||||||
<ColumnSelect v-if="table != ''" v-model="columnSelect" :table="table" />
|
<ColumnSelect v-if="table != ''" v-model="columnSelect" :table="table" />
|
||||||
<Where v-if="table != ''" v-model="where" :table="table" />
|
<Where v-if="table != ''" v-model="where" :table="table" />
|
||||||
<Join v-if="table != ''" v-model="modelValue.join" :table="table" :alreadyJoined="alreadyJoined" />
|
<Order v-if="table != ''" v-model="order" :table="table" :columns="columnSelect" />
|
||||||
<Order v-if="table != '' && enableOrder" v-model="order" :table="table" :columns="nestedTablesByDepth" />
|
<Join v-if="table != ''" v-model="modelValue.join" :table="table" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineComponent, type PropType } from "vue";
|
import { defineComponent, type PropType } from "vue";
|
||||||
import { type ConditionStructure, type DynamicQueryStructure, type OrderByStructure } from "@/types/dynamicQueries";
|
import { mapActions, mapState } from "pinia";
|
||||||
|
import type { ConditionStructure, DynamicQueryStructure, OrderByStructure } from "@/types/dynamicQueries";
|
||||||
|
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
||||||
import ColumnSelect from "./ColumnSelect.vue";
|
import ColumnSelect from "./ColumnSelect.vue";
|
||||||
import Where from "./Where.vue";
|
import Where from "./Where.vue";
|
||||||
import Order from "./Order.vue";
|
import Order from "./Order.vue";
|
||||||
|
@ -23,38 +25,21 @@ export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Object as PropType<DynamicQueryStructure>,
|
type: Object as PropType<DynamicQueryStructure>,
|
||||||
required: true,
|
default: {
|
||||||
|
select: "*",
|
||||||
|
table: "",
|
||||||
|
where: [],
|
||||||
|
join: [],
|
||||||
|
orderBy: [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
disableTableSelect: {
|
disableTableSelect: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
enableOrder: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
emits: ["update:model-value"],
|
emits: ["update:model-value"],
|
||||||
computed: {
|
computed: {
|
||||||
alreadyJoined() {
|
|
||||||
return this.modelValue.join?.map((j) => j.table);
|
|
||||||
},
|
|
||||||
nestedTablesByDepth() {
|
|
||||||
const tables: Array<{ table: string; id: string; depth: number; path: string[]; columns: "*" | string[] }> = [];
|
|
||||||
|
|
||||||
function recurse(item: DynamicQueryStructure, path: string[]) {
|
|
||||||
tables.push({ table: item.table, id: item.id, depth: path.length, path, columns: item.select });
|
|
||||||
if (item.join) {
|
|
||||||
item.join.forEach((child) => {
|
|
||||||
recurse(child, [...path, item.table]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recurse(this.modelValue, []);
|
|
||||||
|
|
||||||
return tables;
|
|
||||||
},
|
|
||||||
table: {
|
table: {
|
||||||
get() {
|
get() {
|
||||||
return this.modelValue.table || "";
|
return this.modelValue.table || "";
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
export interface DynamicQueryStructure {
|
export interface DynamicQueryStructure {
|
||||||
id: string;
|
|
||||||
select: string[] | "*";
|
select: string[] | "*";
|
||||||
table: string;
|
table: string;
|
||||||
where?: Array<ConditionStructure>;
|
where?: Array<ConditionStructure>;
|
||||||
join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
|
join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
|
||||||
orderBy?: Array<OrderByStructure>; // only at top level
|
orderBy?: Array<OrderByStructure>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConditionStructure = (
|
export type ConditionStructure = (
|
||||||
|
@ -49,9 +48,6 @@ export type WhereOperation =
|
||||||
// TODO: age between | age equals | age greater | age smaller
|
// TODO: age between | age equals | age greater | age smaller
|
||||||
|
|
||||||
export type OrderByStructure = {
|
export type OrderByStructure = {
|
||||||
id: string;
|
|
||||||
depth: number;
|
|
||||||
table: string;
|
|
||||||
column: string;
|
column: string;
|
||||||
order: OrderByType;
|
order: OrderByType;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue