Вы можете создать массив свойств для извлечения из this
, затем .map
it:
const props = 'uuid email pass device user pet gold is_active'.split(' ');
db.run(
`INSERT INTO accounts(uuid, email, pass, device, user, pet, gold, is_active) VALUES(?, ?, ?, ?, ?, ?, ?, ?)`,
props.map(prop => this[prop]),
function(err) {
if (err) {
return console.log(err.message);
}
}
);
Может быть еще менее повторяющимся (и менее подверженным ошибкам), сохранив строку свойства, так что вы можете разделить на него и передать первый аргумент .run
:
const propsStr = 'uuid, email, pass, device, user, pet, gold, is_active';
const props = propsStr.split(', ');
db.run(
`INSERT INTO accounts(${propsStr}) VALUES(${propsStr.replace(/\w+/g, '?')})`,
props.map(prop => this[prop]),
function(err) {
if (err) {
return console.log(err.message);
}
}
);