当前位置:网站首页>node の SQLite
node の SQLite
2022-07-06 09:39:00 【InfoQ】
node操作SQLite
mongodb
SQLite
SQLite
安装sqlite3库
node
sqlite3
yarn add sqlite3 -D

创建sqlite数据库
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('数据库连接')
})
}

创建表格并插入数据
db.run
// 执行sql语句
function runSQL(sqlstr) {
db.serialize(()=>{
db.run(sqlstr);
})
}
let db = null;
function SQLiteInit() {
// 连接数据库
let rootPath = path.join(__dirname, '../sqlite3.db');
db = new sqlite3.Database(rootPath)
// 创建表格
runSQL(`
create table worker
(
name text not null,
age int not null,
hobby text not null
);
`)
// 关闭连接
db.close();
}
db.run
prepare
let doc = [{
name: '张三',
age: 18,
hobby: '打李四',
},
{
name: '李四',
age: 18,
hobby: '打王五',
},
{
name: '王五',
age: 18,
hobby: '打张三',
},
]
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
的
sqlite
插件
sqlite
vs code
sqlite

sqlite3.db
Ctrl+Shift+P
sqlite
Open Database

SQLITE EXPLORER
sqlite3.db
New Query

.sql
-- SQLite
select * from worker


边栏推荐
- [VNCTF 2022]ezmath wp
- Hongmeng introduction and development environment construction
- 02个人研发的产品及推广-短信平台
- RepPoints:可形变卷积的进阶
- Case: check the empty field [annotation + reflection + custom exception]
- Unity小技巧 - 绘制瞄准准心
- Integrated development management platform
- Flink parsing (IV): recovery mechanism
- Solr appears write Lock, solrexception: could not get leader props in the log
- 2022年大厂Android面试题汇总(二)(含答案)
猜你喜欢
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
Akamai talking about risk control principles and Solutions
微信防撤回是怎么实现的?
Basic configuration and use of spark
网络分层概念及基本知识
Models used in data warehouse modeling and layered introduction
Flink parsing (IV): recovery mechanism
[translation] principle analysis of X Window Manager (I)
Interpretation of Flink source code (II): Interpretation of jobgraph source code
Concept and basic knowledge of network layering
随机推荐
轻量级计划服务工具研发与实践
C#版Selenium操作Chrome全屏模式显示(F11)
CTF reverse entry question - dice
Vscode replaces commas, or specific characters with newlines
Basic configuration and use of spark
微信小程序获取手机号
基于Infragistics.Document.Excel导出表格的类
BearPi-HM_ Nano development environment
Solrcloud related commands
Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
Automatic operation and maintenance sharp weapon ansible Foundation
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
自动化运维利器ansible基础
[ciscn 2021 South China]rsa writeup
The art of Engineering
Openharmony developer documentation open source project
Solid principle
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Flexible report v1.0 (simple version)