0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

feat(core): save empty string as null value in DB (#1901)

This commit is contained in:
Xiao Yijun 2022-09-09 11:15:40 +08:00 committed by GitHub
parent f9879df7bd
commit ecdf06ef39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -53,6 +53,10 @@ describe('convertToPrimitiveOrSql()', () => {
expect(convertToPrimitiveOrSql(normalKey, ['bar'])).toEqual('["bar"]');
});
it('converts empty string to null value', () => {
expect(convertToPrimitiveOrSql(normalKey, '')).toEqual(null);
});
it('converts value to sql when key ends with special set and value is number', () => {
for (const value of timestampKeyEndings) {
expect(convertToPrimitiveOrSql(`${normalKey}${value}`, 12_341_234)).toEqual({

View file

@ -47,7 +47,15 @@ export const convertToPrimitiveOrSql = (
return sql`to_timestamp(${value}::double precision / 1000)`;
}
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
if (typeof value === 'number' || typeof value === 'boolean') {
return value;
}
if (typeof value === 'string') {
if (value === '') {
return null;
}
return value;
}