I'm working on a web-app project implementing sqlite. I've ran into an issue where I want to request information from a database, but only from rows with specific indeces. The issue is that the rowid
's in the table are not 1,2,3,... .
Below I've posted:
- code responsible for creating/populating table
- code
console.log
ing therowid
's - the output from (2)
Am I doing something wrong in creating the table, causing this issue? If not, is there a way to reset the rowid
's of the table so that they are 1,2,3,...?
// node.js file filling the database
...
db.serialize(function () {
db.run(
"CREATE TABLE IF NOT EXISTS Movies(title TEXT UNIQUE, image TEXT, description TEXT, duration TEXT, release TEXT, age TEXT, schedule TEXT)"
);
var stmt = db.prepare(
"INSERT OR REPLACE INTO Movies(title, image, description, duration, release, age, schedule) VALUES (?, ?, ?, ?, ?, ?, ?)"
);
const jsondata = JSON.stringify(m.schedule);
stmt.run(
m.title,
m.image,
m.description,
m.duration,
m.release,
m.age,
jsondata
);
stmt.finalize();
});
...
// node.js file handling requests
...
app.get('/moviesJson', (req,res) => {
const sql = 'SELECT rowid FROM Movies;
db.all(sql, (err, rows) => {
if(err) throw err;
console.log(rows);
res.json(rows);
});
});
...
// output
[
{ rowid: 568 }, { rowid: 576 },
{ rowid: 567 }, { rowid: 562 },
{ rowid: 571 }, { rowid: 472 },
{ rowid: 575 }, { rowid: 570 },
{ rowid: 561 }, { rowid: 279 },
{ rowid: 569 }, { rowid: 574 },
{ rowid: 284 }, { rowid: 565 },
{ rowid: 451 }, { rowid: 573 },
{ rowid: 564 }, { rowid: 572 },
{ rowid: 563 }, { rowid: 566 }
]