mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 21:36:00 +00:00
filtering datetime values
This commit is contained in:
@@ -45,6 +45,7 @@ export class FormViewDisplay {
|
|||||||
? cfg.addedColumns
|
? cfg.addedColumns
|
||||||
: [...cfg.addedColumns, column.uniqueName],
|
: [...cfg.addedColumns, column.uniqueName],
|
||||||
}));
|
}));
|
||||||
|
this.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { isTypeDateTime } from 'dbgate-tools';
|
import { isTypeDateTime } from 'dbgate-tools';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
export type FilterMultipleValuesMode = 'is' | 'is_not' | 'contains' | 'begins' | 'ends';
|
export type FilterMultipleValuesMode = 'is' | 'is_not' | 'contains' | 'begins' | 'ends';
|
||||||
|
|
||||||
export function getFilterValueExpression(value, dataType) {
|
export function getFilterValueExpression(value, dataType) {
|
||||||
if (value == null) return 'NULL';
|
if (value == null) return 'NULL';
|
||||||
if (isTypeDateTime(dataType)) return value;
|
if (isTypeDateTime(dataType)) return moment(value).format('YYYY-MM-DD HH:mm:ss');
|
||||||
return `="${value}"`;
|
return `="${value}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ const yearMonthDayCondition = () => value => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const fixedIntervalCondition = (start, end) => () => {
|
const createIntervalCondition = (start, end) => {
|
||||||
return {
|
return {
|
||||||
conditionType: 'and',
|
conditionType: 'and',
|
||||||
conditions: [
|
conditions: [
|
||||||
@@ -157,7 +157,7 @@ const fixedIntervalCondition = (start, end) => () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
conditionType: 'binary',
|
conditionType: 'binary',
|
||||||
operator: '<',
|
operator: '<=',
|
||||||
left: {
|
left: {
|
||||||
exprType: 'placeholder',
|
exprType: 'placeholder',
|
||||||
},
|
},
|
||||||
@@ -170,13 +170,42 @@ const fixedIntervalCondition = (start, end) => () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const fixedMomentIntervalCondition = (intervalType, diff) => {
|
const createDateIntervalCondition = (start, end) => {
|
||||||
return fixedIntervalCondition(
|
return createIntervalCondition(start.format('YYYY-MM-DDTHH:mm:ss.SSS'), end.format('YYYY-MM-DDTHH:mm:ss.SSS'));
|
||||||
moment().add(intervalType, diff).startOf(intervalType).toISOString(),
|
};
|
||||||
moment().add(intervalType, diff).endOf(intervalType).toISOString()
|
|
||||||
|
const fixedMomentIntervalCondition = (intervalType, diff) => () => {
|
||||||
|
return createDateIntervalCondition(
|
||||||
|
moment().add(intervalType, diff).startOf(intervalType),
|
||||||
|
moment().add(intervalType, diff).endOf(intervalType)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const yearMonthDayMinuteCondition = () => value => {
|
||||||
|
const m = value.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)\s+(\d\d?):(\d\d?)/);
|
||||||
|
const year = m[1];
|
||||||
|
const month = m[2];
|
||||||
|
const day = m[3];
|
||||||
|
const hour = m[4];
|
||||||
|
const minute = m[5];
|
||||||
|
const dateObject = new Date(year, month - 1, day, hour, minute);
|
||||||
|
|
||||||
|
return createDateIntervalCondition(moment(dateObject).startOf('minute'), moment(dateObject).endOf('minute'));
|
||||||
|
};
|
||||||
|
|
||||||
|
const yearMonthDaySecondCondition = () => value => {
|
||||||
|
const m = value.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)(T|\s+)(\d\d?):(\d\d?):(\d\d?)/);
|
||||||
|
const year = m[1];
|
||||||
|
const month = m[2];
|
||||||
|
const day = m[3];
|
||||||
|
const hour = m[5];
|
||||||
|
const minute = m[6];
|
||||||
|
const second = m[7];
|
||||||
|
const dateObject = new Date(year, month - 1, day, hour, minute, second);
|
||||||
|
|
||||||
|
return createDateIntervalCondition(moment(dateObject).startOf('second'), moment(dateObject).endOf('second'));
|
||||||
|
};
|
||||||
|
|
||||||
const createParser = (filterType: FilterType) => {
|
const createParser = (filterType: FilterType) => {
|
||||||
const langDef = {
|
const langDef = {
|
||||||
string1: () =>
|
string1: () =>
|
||||||
@@ -209,6 +238,8 @@ const createParser = (filterType: FilterType) => {
|
|||||||
yearNum: () => P.regexp(/\d\d\d\d/).map(yearCondition()),
|
yearNum: () => P.regexp(/\d\d\d\d/).map(yearCondition()),
|
||||||
yearMonthNum: () => P.regexp(/\d\d\d\d-\d\d?/).map(yearMonthCondition()),
|
yearMonthNum: () => P.regexp(/\d\d\d\d-\d\d?/).map(yearMonthCondition()),
|
||||||
yearMonthDayNum: () => P.regexp(/\d\d\d\d-\d\d?-\d\d?/).map(yearMonthDayCondition()),
|
yearMonthDayNum: () => P.regexp(/\d\d\d\d-\d\d?-\d\d?/).map(yearMonthDayCondition()),
|
||||||
|
yearMonthDayMinute: () => P.regexp(/\d\d\d\d-\d\d?-\d\d?\s+\d\d?:\d\d?/).map(yearMonthDayMinuteCondition()),
|
||||||
|
yearMonthDaySecond: () => P.regexp(/\d\d\d\d-\d\d?-\d\d?(\s+|T)\d\d?:\d\d?:\d\d?/).map(yearMonthDaySecondCondition()),
|
||||||
|
|
||||||
value: r => P.alt(...allowedValues.map(x => r[x])),
|
value: r => P.alt(...allowedValues.map(x => r[x])),
|
||||||
valueTestEq: r => r.value.map(binaryCondition('=')),
|
valueTestEq: r => r.value.map(binaryCondition('=')),
|
||||||
@@ -286,6 +317,8 @@ const createParser = (filterType: FilterType) => {
|
|||||||
if (filterType == 'logical') allowedElements.push('true', 'false', 'trueNum', 'falseNum');
|
if (filterType == 'logical') allowedElements.push('true', 'false', 'trueNum', 'falseNum');
|
||||||
if (filterType == 'datetime')
|
if (filterType == 'datetime')
|
||||||
allowedElements.push(
|
allowedElements.push(
|
||||||
|
'yearMonthDaySecond',
|
||||||
|
'yearMonthDayMinute',
|
||||||
'yearMonthDayNum',
|
'yearMonthDayNum',
|
||||||
'yearMonthNum',
|
'yearMonthNum',
|
||||||
'yearNum',
|
'yearNum',
|
||||||
|
|||||||
Reference in New Issue
Block a user