当前位置:网站首页>node の SQLite
node の SQLite
2022-07-06 09:39:00 【InfoQ】
node操作SQLite
mongodbSQLiteSQLite安装sqlite3库
nodesqlite3yarn add sqlite3 -D
创建sqlite数据库
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('数据库连接')
})
}
创建表格并插入数据
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.runpreparelet 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
插件
sqlitevs codesqlite
sqlite3.dbCtrl+Shift+PsqliteOpen Database
SQLITE EXPLORERsqlite3.dbNew Query
.sql-- SQLite
select * from worker

边栏推荐
- Quick start of Hongmeng system
- C# WinForm中DataGridView单元格显示图片
- [ASM] introduction and use of bytecode operation classwriter class
- Grafana 9 正式发布,更易用,更酷炫了!
- Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
- [mmdetection] solves the installation problem
- pip install pyodbc : ERROR: Command errored out with exit status 1
- Based on infragistics Document. Excel export table class
- Kali2021 installation and basic configuration
- How to submit data through post
猜你喜欢

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

The most complete tcpdump and Wireshark packet capturing practice in the whole network

Akamai anti confusion

BearPi-HM_ Nano development board "flower protector" case
![[reverse] repair IAT and close ASLR after shelling](/img/83/1c77e24e9430fb7ea775169a794a28.png)
[reverse] repair IAT and close ASLR after shelling

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

Junit单元测试

Vscode replaces commas, or specific characters with newlines

Unity粒子特效系列-闪星星的宝箱

Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
随机推荐
2022年大厂Android面试题汇总(二)(含答案)
02 personal developed products and promotion - SMS platform
MySQL Advanced (index, view, stored procedures, functions, Change password)
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
关于Selenium启动Chrome浏览器闪退问题
Unity粒子特效系列-闪星星的宝箱
C # nanoframework lighting and key esp32
[mmdetection] solves the installation problem
Guidelines for preparing for the 2022 soft exam information security engineer exam
Interpretation of Flink source code (I): Interpretation of streamgraph source code
应用服务配置器(定时,数据库备份,文件备份,异地备份)
Case: check the empty field [annotation + reflection + custom exception]
How uipath determines that an object is null
Compile and build, from the bottom to the top
Quick start of Hongmeng system
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
Summary of study notes for 2022 soft exam information security engineer preparation
沉淀下来的数据库操作类-C#版(SQL Server)
Vscode matches and replaces the brackets