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

边栏推荐
- 78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
- 中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
- [getting started with MySQL] fourth, explore operators in MySQL with Kiko
- Interpretation of Flink source code (I): Interpretation of streamgraph source code
- Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
- Essai de pénétration du Code à distance - essai du module b
- The art of Engineering (3): do not rely on each other between functions of code robustness
- Unity particle special effects series - treasure chest of shining stars
- Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
- The shell generates JSON arrays and inserts them into the database
猜你喜欢

pip install pyodbc : ERROR: Command errored out with exit status 1

Unity小技巧 - 绘制瞄准准心

06 products and promotion developed by individuals - code statistical tools

Concept and basic knowledge of network layering

PySpark算子处理空间数据全解析(4): 先说说空间运算

SAP UI5 框架的 manifest.json

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

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

C # nanoframework lighting and key esp32

【ASM】字节码操作 ClassWriter 类介绍与使用
随机推荐
Spark calculation operator and some small details in liunx
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Easy introduction to SQL (1): addition, deletion, modification and simple query
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
面试突击63:MySQL 中如何去重?
C # nanoframework lighting and key esp32
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
C version selenium operation chrome full screen mode display (F11)
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
Kernel link script parsing
C# NanoFramework 点灯和按键 之 ESP32
Essai de pénétration du Code à distance - essai du module b
Single responsibility principle
connection reset by peer
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
微信小程序获取手机号
Precipitated database operation class - version C (SQL Server)
How to use scroll bars to dynamically adjust parameters in opencv
Summary of study notes for 2022 soft exam information security engineer preparation
03 products and promotion developed by individuals - plan service configurator v3.0