当前位置:网站首页>node の SQLite
node の SQLite
2022-07-06 17:48:00 【InfoQ】
node operation SQLite
mongodbSQLiteSQLiteinstall sqlite3 library
nodesqlite3yarn add sqlite3 -D
establish sqlite database
new sqlite3.Databasemongodbconst 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.runpreparelet 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
sqlitevs codesqlite
sqlite3.dbCtrl+Shift+PsqliteOpen Database
SQLITE EXPLORERsqlite3.dbNew Query
.sql-- SQLite
select * from worker

边栏推荐
- The NTFS format converter (convert.exe) is missing from the current system
- Sqoop I have everything you want
- Awk command exercise
- Deploy flask project based on LNMP
- Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
- PySpark算子处理空间数据全解析(4): 先说说空间运算
- Integrated development management platform
- 10 advanced concepts that must be understood in learning SQL
- The most complete tcpdump and Wireshark packet capturing practice in the whole network
- 中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
猜你喜欢

Summary of Android interview questions of Dachang in 2022 (II) (including answers)

Application service configurator (regular, database backup, file backup, remote backup)

About selenium starting Chrome browser flash back

酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅

Huawei certified cloud computing hica

Kali2021 installation and basic configuration

Automatic operation and maintenance sharp weapon ansible Foundation

Virtual machine startup prompt probing EDD (edd=off to disable) error

The NTFS format converter (convert.exe) is missing from the current system

SAP UI5 框架的 manifest.json
随机推荐
[ASM] introduction and use of bytecode operation classwriter class
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
Sqoop I have everything you want
Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
网络分层概念及基本知识
Debug xv6
Deploy flask project based on LNMP
In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
自动化运维利器ansible基础
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
The problem of "syntax error" when uipath executes insert statement is solved
Unity粒子特效系列-闪星星的宝箱
How to submit data through post
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
The art of Engineering
Alibaba brand data bank: introduction to the most complete data bank
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
Interpretation of Flink source code (I): Interpretation of streamgraph source code