当前位置:网站首页>node の SQLite
node の SQLite
2022-07-06 17:48:00 【InfoQ】
node operation SQLite
mongodb
SQLite
SQLite
install sqlite3 library
node
sqlite3
yarn add sqlite3 -D

establish sqlite database
new sqlite3.Database
mongodb
const path = require('path');
const sqlite3 = require('sqlite3');
function SQLiteInit() {
let rootPath = path.join(__dirname, '../sqlite3.db');
let db = new sqlite3.Database(rootPath, (err)=>{
if (err) throw err;
console.log(' Database connection ')
})
}

Create a table and insert data
db.run
// perform sql sentence
function runSQL(sqlstr) {
db.serialize(()=>{
db.run(sqlstr);
})
}
let db = null;
function SQLiteInit() {
// Connect to database
let rootPath = path.join(__dirname, '../sqlite3.db');
db = new sqlite3.Database(rootPath)
// Create a table
runSQL(`
create table worker
(
name text not null,
age int not null,
hobby text not null
);
`)
// Close the connection
db.close();
}
db.run
prepare
let doc = [{
name: ' Zhang San ',
age: 18,
hobby: ' Hit Li Si ',
},
{
name: ' Li Si ',
age: 18,
hobby: ' Beat Wang Wu ',
},
{
name: ' Wang Wu ',
age: 18,
hobby: ' Open three ',
},
]
let insertInfo = db.prepare('insert into worker (name, age, hobby) values (?, ?, ?)')
doc.forEach((item)=>{
insertInfo.run(item.name, item.age, item.hobby);
})
insertInfo.finalize();
vs code
Of
sqlite
plug-in unit
sqlite
vs code
sqlite

sqlite3.db
Ctrl+Shift+P
sqlite
Open Database

SQLITE EXPLORER
sqlite3.db
New Query

.sql
-- SQLite
select * from worker


边栏推荐
- [elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
- 基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
- Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
- Basic configuration and use of spark
- Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
- 遠程代碼執行滲透測試——B模塊測試
- Display picture of DataGridView cell in C WinForm
- Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company
- Pytorch extract middle layer features?
- Easy introduction to SQL (1): addition, deletion, modification and simple query
猜你喜欢
基于STM32+华为云IOT设计的智能路灯
Automatic operation and maintenance sharp weapon ansible Foundation
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
Awk command exercise
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
Sqoop I have everything you want
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
OliveTin能在网页上安全运行shell命令(上)
Virtual machine startup prompt probing EDD (edd=off to disable) error
Integrated development management platform
随机推荐
【MySQL入门】第三话 · MySQL中常见的数据类型
The art of Engineering (1): try to package things that do not need to be exposed
Display picture of DataGridView cell in C WinForm
远程代码执行渗透测试——B模块测试
当前系统缺少NTFS格式转换器(convert.exe)
node の SQLite
Wechat applet obtains mobile number
Huawei certified cloud computing hica
Vscode replaces commas, or specific characters with newlines
EasyCVR授权到期页面无法登录,该如何解决?
sql语句优化,order by desc速度优化
RepPoints:可形变卷积的进阶
OpenCV中如何使用滚动条动态调整参数
The most complete tcpdump and Wireshark packet capturing practice in the whole network
面试突击63:MySQL 中如何去重?
FlutterWeb浏览器刷新后无法回退的解决方案
How to submit data through post
C WinForm series button easy to use
2022年大厂Android面试题汇总(二)(含答案)
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy