最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - A tutorial on SQLite3 for Node.js and a code example explanation wanted - Stack Overflow

programmeradmin0浏览0评论

I am a bit confused with SQLite at the moment, as this is the first time I'm ever using a database. I got sqlite3 from here: .

I'm looking at that example there, some things I do understand, while others I do not. Most of those database commands that are wrapped in .run(), .prepare() and the like give me a hard time.

This is the example:

var usersDB = new sqlite3.Database("databases/users.db");

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

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

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

usersDB.close();

Also, how do I store simple things such as usernames, passwords (do I have to hash them myself?) and emails in the SQLite database on Node.js?

I am a bit confused with SQLite at the moment, as this is the first time I'm ever using a database. I got sqlite3 from here: https://github.com/developmentseed/node-sqlite3.

I'm looking at that example there, some things I do understand, while others I do not. Most of those database commands that are wrapped in .run(), .prepare() and the like give me a hard time.

This is the example:

var usersDB = new sqlite3.Database("databases/users.db");

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

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

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

usersDB.close();

Also, how do I store simple things such as usernames, passwords (do I have to hash them myself?) and emails in the SQLite database on Node.js?

Share Improve this question asked Jun 14, 2012 at 20:29 corazzacorazza 32.4k39 gold badges120 silver badges191 bronze badges 2
  • Hello Bane, your question seems to be a little vague and bordering on using stackoverflow as your personal research machine. It also helps if you could tell us what you have tried and what went wrong. I also checked the link to the github repo and there seems to be a wiki and an example directory. – Pickels Commented Jun 14, 2012 at 20:40
  • Well I'm basically asking for a tutorial aimed at newcommers. – corazza Commented Jun 14, 2012 at 20:42
Add a comment  | 

2 Answers 2

Reset to default 6

There are two distinct things to learn: sqlite the database program, and node-sqlite3 the nodejs module that provides access to the sqlite db services. Your database questions will be best answered by learning about sqlite, the database program first. I would recommend getting and installing sqlite from: http://www.sqlite.org/. The site has good documentation that will help you learn to store user names and passwords. You can create tables from the command line, add data and get as sense of what is going on. After that if you understand the concepts of node.js then node-sqlite3 will make much more sense to you. Otherwise, spend some time with the node.js site.

Maybe you can try node-sqlite from grumdrig. He has a very nice "example-driven" documentation.

发布评论

评论列表(0)

  1. 暂无评论