mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 14:14:10 +00:00
Support biginteger < 2^53
This commit is contained in:
parent
b35712acc5
commit
4ad7f5bd89
@ -378,9 +378,8 @@ const getType = ({ definition, attribute, name, tableExists = false }) => {
|
||||
case 'integer':
|
||||
return client === 'pg' ? 'integer' : 'int';
|
||||
case 'biginteger':
|
||||
if (client === 'pg') return 'bigint';
|
||||
if (client === 'sqlite3') return 'varchar(255)';
|
||||
return 'bigint(53)';
|
||||
if (client === 'sqlite3') return 'bigint(53)'; // no choice until the sqlite3 package supports returning strings for big integers
|
||||
return 'bigint';
|
||||
case 'float':
|
||||
return client === 'pg' ? 'double precision' : 'double';
|
||||
case 'decimal':
|
||||
|
||||
@ -762,9 +762,11 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
||||
];
|
||||
|
||||
const formatter = attributes => {
|
||||
Object.keys(attributes).map(key => {
|
||||
Object.keys(attributes).forEach(key => {
|
||||
const attr = definition.attributes[key] || {};
|
||||
|
||||
if (attributes[key] === null) return;
|
||||
|
||||
if (attr.type === 'json') {
|
||||
attributes[key] = JSON.parse(attributes[key]);
|
||||
}
|
||||
@ -774,11 +776,7 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const strVal =
|
||||
attributes[key] !== null
|
||||
? attributes[key].toString()
|
||||
: attributes[key];
|
||||
|
||||
const strVal = attributes[key].toString();
|
||||
if (strVal === '1') {
|
||||
attributes[key] = true;
|
||||
} else if (strVal === '0') {
|
||||
@ -788,9 +786,16 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (attr.type === 'date' && definition.client == 'sqlite3') {
|
||||
if (attr.type === 'date' && definition.client === 'sqlite3') {
|
||||
attributes[key] = dateFns.parse(attributes[key]);
|
||||
}
|
||||
|
||||
if (
|
||||
attr.type === 'biginteger' &&
|
||||
definition.client === 'sqlite3'
|
||||
) {
|
||||
attributes[key] = attributes[key].toString();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -868,6 +873,9 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
||||
};
|
||||
|
||||
const castValueFromType = (type, value, definition) => {
|
||||
// do not cast null values
|
||||
if (value === null) return null;
|
||||
|
||||
switch (type) {
|
||||
case 'json': {
|
||||
if (definition.client === 'mysql' || definition.client === 'sqlite3') {
|
||||
|
||||
@ -46,7 +46,7 @@ module.exports = (mongoose = Mongoose) => {
|
||||
case 'json':
|
||||
return 'Mixed';
|
||||
case 'biginteger':
|
||||
return 'String';
|
||||
return 'Long';
|
||||
case 'integer':
|
||||
return 'Number';
|
||||
case 'uuid':
|
||||
|
||||
@ -20,7 +20,7 @@ describe('Test type biginteger', () => {
|
||||
}, 60000);
|
||||
|
||||
test('Create entry with value input JSON', async () => {
|
||||
const inputValue = '1223372036854775807';
|
||||
const inputValue = '1223372036854775';
|
||||
const res = await rq.post('/content-manager/explorer/withbiginteger', {
|
||||
body: {
|
||||
field: inputValue,
|
||||
@ -34,7 +34,7 @@ describe('Test type biginteger', () => {
|
||||
});
|
||||
|
||||
test('Create entry with value input Formdata', async () => {
|
||||
const inputValue = '1223372036854775807';
|
||||
const inputValue = '1223372036854775';
|
||||
const res = await rq.post('/content-manager/explorer/withbiginteger', {
|
||||
formData: {
|
||||
data: JSON.stringify({ field: inputValue }),
|
||||
@ -72,7 +72,7 @@ describe('Test type biginteger', () => {
|
||||
});
|
||||
|
||||
test('Updating entry sets the right value and format', async () => {
|
||||
const inputValue = '1223372036854775807';
|
||||
const inputValue = '1223372036854775';
|
||||
const res = await rq.post('/content-manager/explorer/withbiginteger', {
|
||||
body: {
|
||||
field: inputValue,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user