amilajack / erb-sqlite-example

An example of erb with native dependencies (sqlite3 in this case)
MIT License
47 stars 23 forks source link

ERROR when retrieve data from table Sqlite #3

Closed rahmatkruniawan closed 7 years ago

rahmatkruniawan commented 7 years ago

In my first component I put default query like this :

const sqlite3 = require('sqlite3').verbose(); const db = new sqlite3.Database(':memory:');

db.serialize(function() {
    db.run("CREATE TABLE lorem (info TEXT)");

  const stmt = db.prepare("INSERT INTO lorem VALUES (?)");
    for (let i = 0; i < 10; i++) {
      stmt.run("Ipsum " + i);
  }
  stmt.finalize();

  db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
      console.log(row.id + ": " + row.info);
  });  
});

db.close();

But when I access that data I have been inserted, I got some error they said table lorem not found . This is code for retrieve

const sqlite3 = require('sqlite3').verbose(); const db = new sqlite3.Database(':memory:');

db.serialize(function() {
    db.all('SELECT * FROM lorem ', function(row){
        console.log(": " + row);
    });
});

And the error

: Error: SQLITE_ERROR: no such table: lorem

Is it really not able to get data from other components? šŸ˜• Maybe u can gift me some clude šŸ˜„

rahmatkruniawan commented 7 years ago

Solution just change the name your database.

some explanations :

":memory:" for an anonymous in-memory database and an empty string for an anonymous disk-based database. Anonymous databases are not persisted and when closing the database handle, their contents are lost.