2023-11-10 16:00:27 +02:00
|
|
|
<template>
|
|
|
|
<h2 class="tool-title">SQL split IN</h2>
|
|
|
|
<hr class="mt-5 mb-5">
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
<label for="field_name">Field name</label>
|
2024-03-07 13:41:39 +02:00
|
|
|
<input id="field_name" v-model="toolData.fieldName" v-on:keyup="result" placeholder="D.ID" type="text">
|
2023-11-10 16:00:27 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
<label for="data">Data</label>
|
2024-03-07 13:41:39 +02:00
|
|
|
<textarea id="data" v-model="toolData.data" v-on:keyup="result"></textarea>
|
2023-11-10 16:00:27 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
<label for="data_delimiter">Delimiter</label>
|
2024-03-07 13:41:39 +02:00
|
|
|
<input id="data_delimiter" v-model="toolData.dataDelimiter" v-on:keyup="result" placeholder="," type="text">
|
2023-11-10 16:00:27 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
<label>Wrap in quotes</label>
|
|
|
|
|
|
|
|
<div>
|
2024-03-07 13:41:39 +02:00
|
|
|
<input id="wrap_in_quotes_no" value="" name="wrap_in_quotes" v-model="toolData.wrapInQuotes" v-on:change="result" type="radio"> <label for="wrap_in_quotes_no">No</label><br>
|
|
|
|
<input id="wrap_in_quotes_single" value="single" name="wrap_in_quotes" v-model="toolData.wrapInQuotes" v-on:change="result" type="radio"> <label for="wrap_in_quotes_single">Single</label><br>
|
|
|
|
<input id="wrap_in_quotes_double" value="double" name="wrap_in_quotes" v-model="toolData.wrapInQuotes" v-on:change="result" type="radio"> <label for="wrap_in_quotes_double">Double</label>
|
2023-11-10 16:00:27 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
<label for="chunk_by">Chunk by</label>
|
2024-03-07 13:41:39 +02:00
|
|
|
<input id="chunk_by" v-model="toolData.chunkBy" v-on:keyup="result" placeholder="900" min="1" type="number">
|
2023-11-10 16:00:27 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class="mt-5 mb-5">
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
<label for="result">Result</label>
|
2024-03-07 13:41:39 +02:00
|
|
|
<MonacoEditor name="result" language="sql" :value="toolResult"></MonacoEditor>
|
2023-11-10 16:00:27 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-03-07 13:41:39 +02:00
|
|
|
import MonacoEditor from "@/components/MonacoEditor.vue";
|
|
|
|
|
2023-11-10 16:00:27 +02:00
|
|
|
function arrayChunk(arr, chunkSize) {
|
|
|
|
const res = [];
|
|
|
|
while (arr.length > 0) {
|
|
|
|
const chunk = arr.splice(0, chunkSize);
|
|
|
|
res.push(chunk);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2024-03-07 13:41:39 +02:00
|
|
|
components: {
|
|
|
|
MonacoEditor
|
|
|
|
},
|
2023-11-10 16:00:27 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
toolData: {
|
|
|
|
fieldName: '',
|
|
|
|
data: '',
|
|
|
|
dataDelimiter: '',
|
|
|
|
wrapInQuotes: '',
|
|
|
|
chunkBy: 900,
|
|
|
|
},
|
2024-03-07 13:41:39 +02:00
|
|
|
toolResult: '',
|
2023-11-10 16:00:27 +02:00
|
|
|
};
|
|
|
|
},
|
2024-03-07 13:41:39 +02:00
|
|
|
methods: {
|
|
|
|
result() {
|
2023-11-10 16:00:27 +02:00
|
|
|
let data = this.toolData.data
|
|
|
|
.split(this.toolData.dataDelimiter ? this.toolData.dataDelimiter : '\n');
|
|
|
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
let value = data[i];
|
|
|
|
|
|
|
|
switch (this.toolData.wrapInQuotes) {
|
|
|
|
case 'single':
|
|
|
|
value = "'" + value.replace("'", "\\'") + "'";
|
|
|
|
break;
|
|
|
|
case 'double':
|
|
|
|
value = '"' + value.replace('"', '\\"') + '"';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data[i] = value;
|
|
|
|
}
|
|
|
|
|
2023-11-28 11:03:46 +02:00
|
|
|
const chunkBy = this.toolData.chunkBy > 0 ? this.toolData.chunkBy : 1;
|
|
|
|
data = arrayChunk(data, chunkBy);
|
2023-11-10 16:00:27 +02:00
|
|
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
let chunk = data[i];
|
|
|
|
|
|
|
|
data[i] = '(' + chunk.join(',') + ')';
|
|
|
|
}
|
|
|
|
|
2024-03-07 13:41:39 +02:00
|
|
|
this.toolResult = '(' + this.toolData.fieldName + ' IN ' + data.join(' OR ' + this.toolData.fieldName + ' IN ') + ')';
|
2023-11-10 16:00:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
|
|
</style>
|