From 9f9c63bfcc3423bfeef143cd835f48c62900a799 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Tue, 10 Oct 2023 18:36:35 +0200 Subject: [PATCH] feat: "now" and "random" options added in datetime related data in insert rows tool, closes #402 --- src/common/FakerMethods.ts | 3 + src/common/interfaces/antares.ts | 3 +- src/common/libs/fakerCustom.ts | 17 +++ src/main/ipc-handlers/tables.ts | 12 +- .../components/WorkspaceTabQueryTable.vue | 112 +++++++++--------- .../WorkspaceTabQueryTableContext.vue | 6 +- 6 files changed, 83 insertions(+), 70 deletions(-) create mode 100644 src/common/libs/fakerCustom.ts diff --git a/src/common/FakerMethods.ts b/src/common/FakerMethods.ts index 128720c7..400d72ed 100644 --- a/src/common/FakerMethods.ts +++ b/src/common/FakerMethods.ts @@ -51,6 +51,7 @@ export default class { { name: 'collation', group: 'database', types: ['string'] }, { name: 'engine', group: 'database', types: ['string'] }, + { name: 'now', group: 'date', types: ['string', 'datetime'] }, { name: 'past', group: 'date', types: ['string', 'datetime'] }, { name: 'future', group: 'date', types: ['string', 'datetime'] }, // { name: 'between', group: 'date', types: ['string'] }, @@ -161,7 +162,9 @@ export default class { { name: 'filePath', group: 'system', types: ['string'] }, { name: 'semver', group: 'system', types: ['string'] }, + { name: 'now', group: 'time', types: ['string', 'time'] }, { name: 'recent', group: 'time', types: ['string', 'time'] }, + { name: 'random', group: 'time', types: ['string', 'time'] }, { name: 'vehicle', group: 'vehicle', types: ['string'] }, { name: 'manufacturer', group: 'vehicle', types: ['string'] }, diff --git a/src/common/interfaces/antares.ts b/src/common/interfaces/antares.ts index 6855cbf7..45fc5ee7 100644 --- a/src/common/interfaces/antares.ts +++ b/src/common/interfaces/antares.ts @@ -363,8 +363,7 @@ export interface QueryBuilderObject { offset: number; join: string[]; update: string[]; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - insert: {[key: string]: any}[]; + insert: {[key: string]: string | boolean | number }[]; delete: boolean; } diff --git a/src/common/libs/fakerCustom.ts b/src/common/libs/fakerCustom.ts new file mode 100644 index 00000000..17e9b250 --- /dev/null +++ b/src/common/libs/fakerCustom.ts @@ -0,0 +1,17 @@ +import { faker } from '@faker-js/faker'; +import * as moment from 'moment'; + +export const fakerCustom = { + seed: faker.seed, + setLocale: faker.setLocale, + ...faker, + date: { + now: () => moment().format('YYYY-MM-DD HH:mm:ss'), + ...faker.date + }, + time: { + now: () => moment().format('HH:mm:ss'), + random: () => moment(faker.date.recent()).format('HH:mm:ss'), + ...faker.time + } +}; diff --git a/src/main/ipc-handlers/tables.ts b/src/main/ipc-handlers/tables.ts index d5221077..751846de 100644 --- a/src/main/ipc-handlers/tables.ts +++ b/src/main/ipc-handlers/tables.ts @@ -1,8 +1,8 @@ -import { faker } from '@faker-js/faker'; import customizations from 'common/customizations'; import { ARRAY, BIT, BLOB, BOOLEAN, DATE, DATETIME, FLOAT, LONG_TEXT, NUMBER, TEXT, TEXT_SEARCH } from 'common/fieldTypes'; import * as antares from 'common/interfaces/antares'; import { InsertRowsParams } from 'common/interfaces/tableApis'; +import { fakerCustom } from 'common/libs/fakerCustom'; import { sqlEscaper } from 'common/libs/sqlUtils'; import { ipcMain } from 'electron'; import * as fs from 'fs'; @@ -371,19 +371,19 @@ export default (connections: {[key: string]: antares.Client}) => { let fakeValue; if (params.locale) - faker.locale = params.locale; + fakerCustom.locale = params.locale; if (Object.keys(params.row[key].params).length) { Object.keys(params.row[key].params).forEach(param => { - if (!isNaN(params.row[key].params[param])) - parsedParams[param] = +params.row[key].params[param]; + if (!isNaN(params.row[key].params[param]))// Converts string numerics params to number + parsedParams[param] = Number(params.row[key].params[param]); }); // eslint-disable-next-line @typescript-eslint/no-explicit-any - fakeValue = (faker as any)[params.row[key].group][params.row[key].method](parsedParams); + fakeValue = (fakerCustom as any)[params.row[key].group][params.row[key].method](parsedParams); } else // eslint-disable-next-line @typescript-eslint/no-explicit-any - fakeValue = (faker as any)[params.row[key].group][params.row[key].method](); + fakeValue = (fakerCustom as any)[params.row[key].group][params.row[key].method](); if (typeof fakeValue === 'string') { if (params.row[key].length) diff --git a/src/renderer/components/WorkspaceTabQueryTable.vue b/src/renderer/components/WorkspaceTabQueryTable.vue index 7d4d47e3..1b58191a 100644 --- a/src/renderer/components/WorkspaceTabQueryTable.vue +++ b/src/renderer/components/WorkspaceTabQueryTable.vue @@ -3,7 +3,7 @@ ref="tableWrapper" class="vscroll no-outline" tabindex="0" - :style="{'height': resultsSize+'px'}" + :style="{ 'height': resultsSize + 'px' }" @blur="deselectRows" @focus="hasFocus = true" @keyup.delete="showDeleteConfirmModal" @@ -28,7 +28,7 @@ v-for="(result, index) in resultsWithRows" :key="index" class="tab-item" - :class="{'active': resultsetIndex === index}" + :class="{ 'active': resultsetIndex === index }" @click="selectResultset(index)" > {{ result.fields ? result.fields[0]?.table : '' }} ({{ result.rows.length }}) @@ -57,7 +57,7 @@ {{ field.alias || field.name }} @@ -90,7 +90,7 @@ :fields="fieldsObj" :key-usage="keyUsage" :element-type="elementType" - :class="{'selected': selectedRows.includes(row._antares_id)}" + :class="{ 'selected': selectedRows.includes(row._antares_id) }" :selected="selectedRows.includes(row._antares_id)" :selected-cell="selectedRows.length === 1 && selectedRows.includes(row._antares_id) ? selectedField : null" @start-editing="isEditingRow = true" @@ -163,7 +163,7 @@ @@ -208,9 +208,9 @@ v-model="csvExportOptions.stringDelimiter" class="form-select" :options="[ - {value: '', label: t('general.none')}, - {value: 'single', label: t('general.singleQuote')}, - {value: 'double', label: t('general.doubleQuote')} + { value: '', label: t('general.none') }, + { value: 'single', label: t('general.singleQuote') }, + { value: 'double', label: t('general.doubleQuote') } ]" /> @@ -235,7 +235,10 @@
-