Datetime fields precision

This commit is contained in:
Fabio 2020-07-05 16:06:56 +02:00
parent 262a476f50
commit 187b4f50f9
6 changed files with 53 additions and 19 deletions

View File

@ -7,7 +7,7 @@ import Generic from '../models/Generic';
export default (connections) => {
ipcMain.handle('getTableColumns', async (event, { uid, schema, table }) => {
try {
const result = await InformationSchema.getTableColumns(connections[uid], schema, table);
const result = await InformationSchema.getTableColumns(connections[uid], schema, table);// TODO: uniform column properties
return { status: 'success', response: result };
}
catch (err) {

View File

@ -77,7 +77,8 @@ export default {
return {
name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE
type: field.DATA_TYPE,
precision: field.DATETIME_PRECISION
};
}).filter(field => {
if (this.results.fields) {

View File

@ -39,6 +39,7 @@
:key="cKey"
:content="col"
:field="cKey"
:precision="fieldPrecision(cKey)"
:type="fieldType(cKey)"
@updateField="updateField($event, row[primaryField.name])"
/>
@ -105,6 +106,14 @@ export default {
return type;
},
fieldPrecision (cKey) {
let length = 0;
const field = this.fields.filter(field => field.name === cKey)[0];
if (field)
length = field.precision;
return length;
},
keyName (key) {
switch (key) {
case 'pri':

View File

@ -11,9 +11,10 @@
class="cell-content px-2"
:class="isNull(content)"
@dblclick="editON"
>{{ content | typeFormat(type) }}</span>
>{{ content | typeFormat(type, precision) }}</span>
<template v-else>
<input
v-else
v-if="inputProps.mask"
ref="editField"
v-model="localContent"
v-mask="inputProps.mask"
@ -22,6 +23,16 @@
class="editable-field px-2"
@blur="editOFF"
>
<input
v-else
ref="editField"
v-model="localContent"
:type="inputProps.type"
autofocus
class="editable-field px-2"
@blur="editOFF"
>
</template>
</div>
</template>
@ -34,7 +45,7 @@ import { mask } from 'vue-the-mask';
export default {
name: 'WorkspaceQueryTableCell',
filters: {
typeFormat (val, type) {
typeFormat (val, type, precision) {
if (!val) return val;
switch (type) {
@ -48,7 +59,11 @@ export default {
}
case 'datetime':
case 'timestamp': {
return moment(val).isValid() ? moment(val).format('YYYY-MM-DD HH:mm:ss.SSS') : val;
let datePrecision = '';
for (let i = 0; i < precision; i++)
datePrecision += i === 0 ? '.S' : 'S';
return moment(val).isValid() ? moment(val).format(`YYYY-MM-DD HH:mm:ss${datePrecision}`) : val;
}
case 'blob':
case 'mediumblob':
@ -74,6 +89,7 @@ export default {
props: {
type: String,
field: String,
precision: [Number, null],
content: [String, Number, Object, Date, Uint8Array]
},
data () {
@ -98,12 +114,17 @@ export default {
case 'date':
return { type: 'text', mask: '####-##-##' };
case 'datetime':
case 'timestamp':
return { type: 'text', mask: '####-##-## ##:##:##.###' };// TODO: field length
case 'timestamp': {
let datetimeMask = '####-##-## ##:##:##';
for (let i = 0; i < this.precision; i++)
datetimeMask += i === 0 ? '.#' : '#';
return { type: 'text', mask: datetimeMask };
}
case 'blob':
case 'mediumblob':
case 'longblob':
case 'bit':
return { type: 'file', mask: false };
default:
return 'hidden';
}
@ -114,6 +135,8 @@ export default {
return value === null ? ' is-null' : '';
},
editON () {
if (['file'].includes(this.inputProps.type)) return;// TODO: remove temporary file block
this.$nextTick(() => {
this.$refs.cell.blur();

View File

@ -75,7 +75,8 @@ export default {
return {
name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE
type: field.DATA_TYPE,
precision: field.DATETIME_PRECISION
};
});
}

View File

@ -17,7 +17,7 @@ module.exports = {
{
loader: 'sass-loader',
options: {
prependData: '@import "@/scss/_variables.scss";'
additionalData: '@import "@/scss/_variables.scss";'
}
}
]