当前位置:网站首页>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

边栏推荐
- Integrated development management platform
- Awk command exercise
- Guidelines for preparing for the 2022 soft exam information security engineer exam
- Flink parsing (III): memory management
- Huawei certified cloud computing hica
- 微信小程序获取手机号
- 在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
- RepPoints:可形变卷积的进阶
- 酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
- Essai de pénétration du Code à distance - essai du module b
猜你喜欢

网络分层概念及基本知识

Alibaba brand data bank: introduction to the most complete data bank

2022年大厂Android面试题汇总(一)(含答案)

JMeter interface test response data garbled

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

BearPi-HM_ Nano development environment

02 personal developed products and promotion - SMS platform

Vscode matches and replaces the brackets

学 SQL 必须了解的 10 个高级概念

分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
随机推荐
Selenium test of automatic answer runs directly in the browser, just like real users.
Alibaba brand data bank: introduction to the most complete data bank
Sqoop I have everything you want
SQL statement optimization, order by desc speed optimization
面试突击62:group by 有哪些注意事项?
BearPi-HM_ Nano development environment
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
基于STM32+华为云IOT设计的智能路灯
02 personal developed products and promotion - SMS platform
Essai de pénétration du Code à distance - essai du module b
TCP connection is more than communicating with TCP protocol
Flink analysis (I): basic concept analysis
RepPoints:可形变卷积的进阶
node の SQLite
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
JMeter interface test response data garbled
重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Flet教程之 13 ListView最常用的滚动控件 基础入门(教程含源码)