Do not parse date types

This commit is contained in:
Alexandre Bodin 2019-12-05 12:29:24 +01:00
parent dd072c40c3
commit f55e1f704b
5 changed files with 13 additions and 21 deletions

View File

@ -64,8 +64,9 @@ module.exports = async ({
case 'text':
return table.text(name, 'longtext');
case 'json':
// return client === 'pg' ? 'jsonb' : 'longtext';
return table.jsonb(name);
return definition.client === 'pg'
? table.jsonb(name)
: table.text(name, 'longtext');
case 'enumeration':
return table.enu(name, attribute.enum || []);
case 'string':

View File

@ -57,22 +57,6 @@ const formatters = {
return value.toString();
},
},
mysql: {
boolean: value => {
if (typeof value === 'boolean') {
return value;
}
const strVal = value.toString();
if (strVal === '1') {
return true;
} else if (strVal === '0') {
return false;
} else {
return null;
}
},
},
};
module.exports = {

View File

@ -78,7 +78,10 @@ const createComponentJoinTables = async ({ definition, ORM }) => {
.notNullable();
table.string('component_type').notNullable();
table.integer('component_id').notNullable();
table.integer(joinColumn).notNullable();
table
.integer(joinColumn)
.unsigned()
.notNullable();
table
.foreign(joinColumn)

View File

@ -615,7 +615,7 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
});
this.on('saving', (instance, attrs) => {
instance.attributes = mapper(attrs);
instance.attributes = _.assign(instance.attributes, mapper(attrs));
return _.isFunction(target[model.toLowerCase()]['beforeSave'])
? target[model.toLowerCase()]['beforeSave']
@ -632,7 +632,7 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
function formatOutput(instance) {
if (Array.isArray(instance.models)) {
instance.models.map(formatEntry);
instance.models.forEach(entry => formatEntry(entry));
} else {
formatEntry(instance);
}

View File

@ -8,6 +8,8 @@ const timeRegex = new RegExp(
);
const parseTime = value => {
if (dates.isDate(value)) return dates.format(value, 'HH:mm:ss.SSS');
if (typeof value !== 'string') {
throw new Error(`Expected a string, got a ${typeof value}`);
}
@ -24,6 +26,7 @@ const parseTime = value => {
};
const parseDate = value => {
if (dates.isDate(value)) return dates.format(value, 'yyyy-MM-dd');
try {
let date = dates.parseISO(value);
@ -36,6 +39,7 @@ const parseDate = value => {
};
const parseDateTimeOrTimestamp = value => {
if (dates.isDate(value)) return value;
try {
const date = dates.parseISO(value);
if (dates.isValid(date)) return date;