当前位置:网站首页>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
边栏推荐
- 04 products and promotion developed by individuals - data push tool
- 【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
- Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company
- Automatic operation and maintenance sharp weapon ansible Foundation
- Unity particle special effects series - treasure chest of shining stars
- Interpretation of Flink source code (I): Interpretation of streamgraph source code
- Flink analysis (I): basic concept analysis
- The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
- The NTFS format converter (convert.exe) is missing from the current system
- 2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
猜你喜欢
EasyCVR授权到期页面无法登录,该如何解决?
How to use scroll bars to dynamically adjust parameters in opencv
Unity小技巧 - 绘制瞄准准心
Unity particle special effects series - treasure chest of shining stars
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
【ASM】字节码操作 ClassWriter 类介绍与使用
【MySQL入门】第一话 · 初入“数据库”大陆
04 products and promotion developed by individuals - data push tool
随机推荐
微信小程序获取手机号
connection reset by peer
PyTorch 提取中间层特征?
Compile and build, from the bottom to the top
Huawei certified cloud computing hica
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Development and practice of lightweight planning service tools
Grafana 9 正式发布,更易用,更酷炫了!
当前系统缺少NTFS格式转换器(convert.exe)
EasyCVR授权到期页面无法登录,该如何解决?
The shell generates JSON arrays and inserts them into the database
C WinForm series button easy to use
JMeter interface test response data garbled
Example of batch update statement combining update and inner join in SQL Server
Flink analysis (II): analysis of backpressure mechanism
SAP UI5 框架的 manifest.json
Single responsibility principle
C version selenium operation chrome full screen mode display (F11)
Quick start of Hongmeng system
PySpark算子处理空间数据全解析(4): 先说说空间运算