Skip to content

Commit

Permalink
fix: fix #2698
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Dec 8, 2024
1 parent d3ed681 commit 79c6263
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/server/src/service/storage/postgresql.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
const MySQL = require('./mysql.js');

function mapKeys({ insertedat, createdat, updatedat, ...item }) {
const mapFields = {
insertedAt: insertedat,
createdAt: createdat,
updatedAt: updatedat,
};

for (const field in mapFields) {
if (!mapFields[field]) {
continue;
}
item[field] = mapFields[field];
}

return item;
}
module.exports = class extends MySQL {
model(tableName) {
return super.model(tableName.toLowerCase());
Expand All @@ -22,22 +38,7 @@ module.exports = class extends MySQL {

const data = await super.select(lowerWhere, options);

return data.map(({ insertedat, createdat, updatedat, ...item }) => {
const mapFields = {
insertedAt: insertedat,
createdAt: createdat,
updatedAt: updatedat,
};

for (const field in mapFields) {
if (!mapFields[field]) {
continue;
}
item[field] = mapFields[field];
}

return item;
});
return data.map(mapKeys);
}

async add(data) {
Expand All @@ -53,7 +54,7 @@ module.exports = class extends MySQL {
delete data[key];
});

return super.add(data);
return super.add(data).then(mapKeys);
}

async count(...args) {
Expand Down

0 comments on commit 79c6263

Please sign in to comment.