refactor(update-config): introduce updateFirstOrInsert via query builder

This commit is contained in:
Ali BARIN
2024-09-23 10:41:23 +00:00
parent 9be75e56e7
commit c732fe16b3
2 changed files with 30 additions and 11 deletions

View File

@@ -53,6 +53,18 @@ class ExtendedQueryBuilder extends Model.QueryBuilder {
[DELETED_COLUMN_NAME]: null,
});
}
async updateFirstOrInsert(data = {}) {
let firstRow = await this.first();
if (firstRow) {
return firstRow.$query().patchAndFetch(data);
}
const newInstance = this.insertAndFetch(data);
return newInstance;
}
}
export default ExtendedQueryBuilder;