有关SQLite3的Node.js教程和代码示例解释 [英] A tutorial on SQLite3 for Node.js and a code example explanation wanted

查看:279
本文介绍了有关SQLite3的Node.js教程和代码示例解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有点困惑与SQLite,因为这是我第一次使用数据库。我从这里获得了sqlite3: https://github.com/developmentseed/node-sqlite3

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.

我在看那个例子,有些事情我明白,而其他的我不知道。包含在 .run() .prepare()等中的大多数数据库命令给了我一个困难时期。

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.

这是一个例子:

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?

推荐答案

也许你可以尝试 node-sqlite从grumdrig 。他有非常好的示例驱动文档

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

这篇关于有关SQLite3的Node.js教程和代码示例解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆