mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat: "now" and "random" options added in datetime related data in insert rows tool, closes #402
This commit is contained in:
@ -51,6 +51,7 @@ export default class {
|
|||||||
{ name: 'collation', group: 'database', types: ['string'] },
|
{ name: 'collation', group: 'database', types: ['string'] },
|
||||||
{ name: 'engine', 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: 'past', group: 'date', types: ['string', 'datetime'] },
|
||||||
{ name: 'future', group: 'date', types: ['string', 'datetime'] },
|
{ name: 'future', group: 'date', types: ['string', 'datetime'] },
|
||||||
// { name: 'between', group: 'date', types: ['string'] },
|
// { name: 'between', group: 'date', types: ['string'] },
|
||||||
@ -161,7 +162,9 @@ export default class {
|
|||||||
{ name: 'filePath', group: 'system', types: ['string'] },
|
{ name: 'filePath', group: 'system', types: ['string'] },
|
||||||
{ name: 'semver', 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: 'recent', group: 'time', types: ['string', 'time'] },
|
||||||
|
{ name: 'random', group: 'time', types: ['string', 'time'] },
|
||||||
|
|
||||||
{ name: 'vehicle', group: 'vehicle', types: ['string'] },
|
{ name: 'vehicle', group: 'vehicle', types: ['string'] },
|
||||||
{ name: 'manufacturer', group: 'vehicle', types: ['string'] },
|
{ name: 'manufacturer', group: 'vehicle', types: ['string'] },
|
||||||
|
@ -363,8 +363,7 @@ export interface QueryBuilderObject {
|
|||||||
offset: number;
|
offset: number;
|
||||||
join: string[];
|
join: string[];
|
||||||
update: string[];
|
update: string[];
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
insert: {[key: string]: string | boolean | number }[];
|
||||||
insert: {[key: string]: any}[];
|
|
||||||
delete: boolean;
|
delete: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
src/common/libs/fakerCustom.ts
Normal file
17
src/common/libs/fakerCustom.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
|
};
|
@ -1,8 +1,8 @@
|
|||||||
import { faker } from '@faker-js/faker';
|
|
||||||
import customizations from 'common/customizations';
|
import customizations from 'common/customizations';
|
||||||
import { ARRAY, BIT, BLOB, BOOLEAN, DATE, DATETIME, FLOAT, LONG_TEXT, NUMBER, TEXT, TEXT_SEARCH } from 'common/fieldTypes';
|
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 * as antares from 'common/interfaces/antares';
|
||||||
import { InsertRowsParams } from 'common/interfaces/tableApis';
|
import { InsertRowsParams } from 'common/interfaces/tableApis';
|
||||||
|
import { fakerCustom } from 'common/libs/fakerCustom';
|
||||||
import { sqlEscaper } from 'common/libs/sqlUtils';
|
import { sqlEscaper } from 'common/libs/sqlUtils';
|
||||||
import { ipcMain } from 'electron';
|
import { ipcMain } from 'electron';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
@ -371,19 +371,19 @@ export default (connections: {[key: string]: antares.Client}) => {
|
|||||||
let fakeValue;
|
let fakeValue;
|
||||||
|
|
||||||
if (params.locale)
|
if (params.locale)
|
||||||
faker.locale = params.locale;
|
fakerCustom.locale = params.locale;
|
||||||
|
|
||||||
if (Object.keys(params.row[key].params).length) {
|
if (Object.keys(params.row[key].params).length) {
|
||||||
Object.keys(params.row[key].params).forEach(param => {
|
Object.keys(params.row[key].params).forEach(param => {
|
||||||
if (!isNaN(params.row[key].params[param]))
|
if (!isNaN(params.row[key].params[param]))// Converts string numerics params to number
|
||||||
parsedParams[param] = +params.row[key].params[param];
|
parsedParams[param] = Number(params.row[key].params[param]);
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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
|
else
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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 (typeof fakeValue === 'string') {
|
||||||
if (params.row[key].length)
|
if (params.row[key].length)
|
||||||
|
@ -235,7 +235,10 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="column col-7">
|
<div class="column col-7">
|
||||||
<label class="form-switch d-inline-block" @click.prevent="csvExportOptions.header = !csvExportOptions.header">
|
<label
|
||||||
|
class="form-switch d-inline-block"
|
||||||
|
@click.prevent="csvExportOptions.header = !csvExportOptions.header"
|
||||||
|
>
|
||||||
<input type="checkbox" :checked="csvExportOptions.header">
|
<input type="checkbox" :checked="csvExportOptions.header">
|
||||||
<i class="form-icon" />
|
<i class="form-icon" />
|
||||||
</label>
|
</label>
|
||||||
@ -249,10 +252,10 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import faker from '@faker-js/faker';
|
|
||||||
import { BLOB, DATE, DATETIME, LONG_TEXT, TEXT, TIME } from 'common/fieldTypes';
|
import { BLOB, DATE, DATETIME, LONG_TEXT, TEXT, TIME } from 'common/fieldTypes';
|
||||||
import { QueryResult, TableField } from 'common/interfaces/antares';
|
import { QueryResult, TableField } from 'common/interfaces/antares';
|
||||||
import { TableUpdateParams } from 'common/interfaces/tableApis';
|
import { TableUpdateParams } from 'common/interfaces/tableApis';
|
||||||
|
import { fakerCustom } from 'common/libs/fakerCustom';
|
||||||
import { jsonToSqlInsert } from 'common/libs/sqlUtils';
|
import { jsonToSqlInsert } from 'common/libs/sqlUtils';
|
||||||
import { uidGen } from 'common/libs/uidGen';
|
import { uidGen } from 'common/libs/uidGen';
|
||||||
import * as json2php from 'json2php';
|
import * as json2php from 'json2php';
|
||||||
@ -670,16 +673,7 @@ const fillCell = (event: { name: string; group: string; type: string }) => {
|
|||||||
datePrecision += i === 0 ? '.S' : 'S';
|
datePrecision += i === 0 ? '.S' : 'S';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.group === 'custom') {
|
fakeValue = (fakerCustom as any)[event.group][event.name]();
|
||||||
if (event.type === 'time' && event.name === 'now')
|
|
||||||
fakeValue = moment().format(`HH:mm:ss${datePrecision}`);
|
|
||||||
else if (event.type === 'time' && event.name === 'random')
|
|
||||||
fakeValue = moment(faker.date.recent()).format(`HH:mm:ss${datePrecision}`);
|
|
||||||
else if (event.type === 'datetime' && event.name === 'now')
|
|
||||||
fakeValue = moment().format(`YYYY-MM-DD HH:mm:ss${datePrecision}`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fakeValue = (faker as any)[event.group][event.name]();
|
|
||||||
if (['string', 'number'].includes(typeof fakeValue)) {
|
if (['string', 'number'].includes(typeof fakeValue)) {
|
||||||
if (typeof fakeValue === 'number')
|
if (typeof fakeValue === 'number')
|
||||||
fakeValue = String(fakeValue);
|
fakeValue = String(fakeValue);
|
||||||
@ -691,7 +685,6 @@ const fillCell = (event: { name: string; group: string; type: string }) => {
|
|||||||
fakeValue = moment(fakeValue).format(`YYYY-MM-DD HH:mm:ss${datePrecision}`);
|
fakeValue = moment(fakeValue).format(`YYYY-MM-DD HH:mm:ss${datePrecision}`);
|
||||||
else if (TIME.includes(selectedCell.value.type))
|
else if (TIME.includes(selectedCell.value.type))
|
||||||
fakeValue = moment(fakeValue).format(`HH:mm:ss${datePrecision}`);
|
fakeValue = moment(fakeValue).format(`HH:mm:ss${datePrecision}`);
|
||||||
}
|
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
primary: primaryField.value?.name,
|
primary: primaryField.value?.name,
|
||||||
@ -1055,6 +1048,7 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.column-resizable {
|
.column-resizable {
|
||||||
|
|
||||||
&:hover,
|
&:hover,
|
||||||
&:active {
|
&:active {
|
||||||
resize: horizontal;
|
resize: horizontal;
|
||||||
|
@ -197,13 +197,13 @@ const fakerMethods = {
|
|||||||
{ name: 'amount', group: 'finance' }
|
{ name: 'amount', group: 'finance' }
|
||||||
],
|
],
|
||||||
datetime: [
|
datetime: [
|
||||||
{ name: 'now', group: 'custom' },
|
{ name: 'now', group: 'date' },
|
||||||
{ name: 'past', group: 'date' },
|
{ name: 'past', group: 'date' },
|
||||||
{ name: 'future', group: 'date' }
|
{ name: 'future', group: 'date' }
|
||||||
],
|
],
|
||||||
time: [
|
time: [
|
||||||
{ name: 'now', group: 'custom' },
|
{ name: 'now', group: 'time' },
|
||||||
{ name: 'random', group: 'custom' }
|
{ name: 'random', group: 'time' }
|
||||||
],
|
],
|
||||||
uuid: [
|
uuid: [
|
||||||
{ name: 'uuid', group: 'random' }
|
{ name: 'uuid', group: 'random' }
|
||||||
|
Reference in New Issue
Block a user