How to Basic CRUD SQLite 3 with VueJs 2

I have a problem with SQlite3 and Vue2

I am using Electron-Vue and I have installed SQLite3 and require it successfully (database.db)

using this:

var sqlite3 = require('sqlite3').verbose();
var path = require('path')
var db = new sqlite3.Database(path.join(__dirname, '..', '/../','db', 'database.db'));

      

So the next step is difficult for me (Basic Crud System)?

How to add this code to Vue component

db.serialize(function() {


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

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

stmt.finalize();

var rows = document.getElementById("database");
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
  var item = document.createElement("li");
  item.textContent = "" + row.id + ": " + row.info;
  rows.appendChild(item);
});
 });

 db.close();

      

Just a simple demo code to get started with VueJS2 Component and SQlite3 !!

+3


source to share





All Articles