关于Node.js的SQLite3教程以及想要的代码示例解释[英] A tutorial on SQLite3 for Node.js and a code example explanation wanted

本文是小编为大家收集整理的关于关于Node.js的SQLite3教程以及想要的代码示例解释的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我目前与sqlite有点混淆,因为这是我第一次使用数据库.我从这里得到了sqlite3: https://github.com/develoverment.com/develovermentseed/node-sqlite/node-sqlite3 .

.

我在那里看那个示例,有些我确实理解,而另一些我不理解.大多数包裹在.run(),.prepare()等中的数据库命令都给我一个困难.

这是一个例子:

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();

另外,我如何存储简单的内容,例如用户名,密码(我必须自己哈希)和node.js上的sqlite数据库中的电子邮件?

推荐答案

也许您可以尝试 grumdrig的node-sqlite .他有一个非常不错

其他推荐答案

有两件不同的知识:SQLITE数据库程序和Node-sqlite3 nodejs模块,该模块可访问SQLITE DB Services.首先了解SQLITE(数据库程序),最好回答您的数据库问题. 我建议从: http://www.sqlite.org/中.该网站具有良好的文档,可以帮助您学习存储用户名和密码.您可以从命令行创建表,添加数据并了解正在发生的事情.之后,如果您了解node.js的概念,那么node-sqlite3对您来说会更有意义.否则,请花一些时间在node.js网站上.

本文地址:https://www.itbaoku.cn/post/597562.html

问题描述

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?

推荐答案

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

其他推荐答案

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.