I
I
IgorPotatoes2021-08-19 12:34:05
SQLite
IgorPotatoes, 2021-08-19 12:34:05

Sqlite is not added to the user, how to fix it?

If more pieces of code are needed, then I will throw off the
error itself:

/root/fake-transfer/index.js:570
                        createUserStatement.run(Object.values(user).map(mapObjectValue));

SqliteError: NOT NULL constraint failed: users.id
    at getOrCreateUser (/root/fake-transfer/index.js:570:24)
    at getUser (/root/fake-transfer/index.js:564:22)
    at getTimeNow (/root/fake-transfer/index.js:609:60)
    at modifyHistoryInput (/root/fake-transfer/index.js:827:13)
    at modifyIPhoneHistoryInput (/root/fake-transfer/index.js:778:14)
    at HistoryType.withItems.size [as modifyInput] (/root/fake-transfer/index.js:378:110)
    at sendFake (/root/fake-transfer/index.js:895:27)


Piece of code:

function getUser(id) {
  return users[id] || getOrCreateUser(id);

  function getOrCreateUser(id) {
    const count = getUserCountStatement.get(id);
    if (count["count()"] == 0) {
      const user = new User(id);
      createUserStatement.run(Object.values(user).map(mapObjectValue)); // 570 error line

      return user;
    }

    users[id] = loadUserStatement.get(id);
    users[id].bills = JSON.parse(users[id].bills);
    return users[id];
  }
}
function saveUser(user) {
  const values = userKeysNoIds.map(x => mapObjectValue(user[x]));
  values.push(user.id);

  updateUserStatement.run(values);
}


An empty database is created
O8jTpgYy4vI.jpg?size=390x101&quality=96&sign=3e3ff4ef9ba767d18eb1c90a46adf705&type=album

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2021-08-19
@deliro

Bro, let me highlight the mistake for you, and you can guess for yourself:
SqliteError: NOT NULL constraint failed: users.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question