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

边栏推荐
- Mysqlimport imports data files into the database
- Based on infragistics Document. Excel export table class
- Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
- Vscode replaces commas, or specific characters with newlines
- PySpark算子处理空间数据全解析(4): 先说说空间运算
- Kali2021 installation and basic configuration
- 分布式不来点网关都说不过去
- Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
- Debug and run the first xv6 program
- [getting started with MySQL] fourth, explore operators in MySQL with Kiko
猜你喜欢

Unity小技巧 - 绘制瞄准准心

Flink analysis (II): analysis of backpressure mechanism

基本磁盘与动态磁盘 RAID磁盘冗余阵列区分

PyTorch 提取中间层特征?
![[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias](/img/03/ece7f7b28cd9caea4240635548c77f.jpg)
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias

在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?

Grafana 9 正式发布,更易用,更酷炫了!

Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)

Flink parsing (IV): recovery mechanism

Application service configurator (regular, database backup, file backup, remote backup)
随机推荐
MySQL advanced (index, view, stored procedure, function, password modification)
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
Kernel link script parsing
connection reset by peer
Flexible report v1.0 (simple version)
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
10 advanced concepts that must be understood in learning SQL
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
Unity粒子特效系列-闪星星的宝箱
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
The solution that flutterweb browser cannot be rolled back after refreshing
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
Flet教程之 13 ListView最常用的滚动控件 基础入门(教程含源码)
Solrcloud related commands
PySpark算子处理空间数据全解析(4): 先说说空间运算
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
[introduction to MySQL] the first sentence · first time in the "database" Mainland
[translation] principle analysis of X Window Manager (I)
Summary of Android interview questions of Dachang in 2022 (I) (including answers)