0

I have to used below code for using sqlite inside angulajs.but i got error like, Module name "sqlite3" has not been loaded yet for context: _. Use require([]) please help me

 var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('mydb.sqlite');
db.serialize(function() {
    console.log("A");
    db.run("CREATE TABLE if not exists lorem (info TEXT)");
    var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
    for (var 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();
2
  • web app or mobile app? Commented Sep 22, 2016 at 6:47
  • webapplication only..... Commented Sep 22, 2016 at 6:50

1 Answer 1

1

You cannot use sqlite3 in angularjs web application directly, because angularjs is client-side frontend framework, and sqlite is a database and a part of the backend.

So you can only use sqlite in your application via backend services implemented on the server side (nodejs, java, ...). And if you need browser data storage mechanism, you can use IndexedDB.

See the similar question here.

Sign up to request clarification or add additional context in comments.

1 Comment

You can take working example from here. It's work for me, but I had to change version for sqlite3 to * (latest) in package.json, because it was the problem with my environment (node 4.4.3, npm 2.15.1).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.