7

第19课:sqlite 3 模块操作 SQLite 数据库

 3 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/108729638
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

虽然 sql.js 在操作 SQLite 数据库方面没什么问题,但由于 sql.js 是基于 JavaScript 的,因而效率较低,而且操作都是在内存中完成的,如果要保存修改,需要将整个数据库写到文件中,比较费事,而且写数据的效率不高,因此在遇到大量数据的情况下,建议使用 Node.js 中的 sqlite 3 模块操作 SQLite 数据库。

19.1 安装 sqlite 3 模块

sqlite 3 并不是 Node.js 的标准模块,因此在使用之前需要在当前工程目录下执行下面的命令进行安装。

npm install --save sqlite3

执行完上面的命令后,会发现当前工程的 node_modules 目录中出现了一个 sqlite 3 目录,还出现了很多其他的目录,这些目录都是 sqlite 3 依赖的 Node.js 模块。

安装完 sqlite 3 模块后,可以创建一个 test.js 文件然后输入下面的代码测试 sqlite 3 模块是否安装成功。

使用下面的命令执行 test.js 脚本文件,如果执行成功,说明 sqlite 3 模块已经安装成功。

node test.js

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK