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

边栏推荐
- Vscode matches and replaces the brackets
- SAP UI5 框架的 manifest.json
- Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
- Kali2021 installation and basic configuration
- How to submit data through post
- Virtual machine startup prompt probing EDD (edd=off to disable) error
- Precipitated database operation class - version C (SQL Server)
- Compile and build, from the bottom to the top
- Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
- Openharmony developer documentation open source project
猜你喜欢

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

虚拟机启动提示Probing EDD (edd=off to disable)错误

Easy introduction to SQL (1): addition, deletion, modification and simple query

Flink parsing (III): memory management

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

C WinForm series button easy to use

Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system

Uipath browser performs actions in the new tab
![[introduction to MySQL] third, common data types in MySQL](/img/11/66b4908ed8f253d599942f35bde96a.png)
[introduction to MySQL] third, common data types in MySQL

10 advanced concepts that must be understood in learning SQL
随机推荐
How to submit data through post
Error: Publish of Process project to Orchestrator failed. The operation has timed out.
Grafana 9 is officially released, which is easier to use and more cool!
Remote code execution penetration test - B module test
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
Concept and basic knowledge of network layering
Optimization of middle alignment of loading style of device player in easycvr electronic map
Unity tips - draw aiming Center
02 personal developed products and promotion - SMS platform
Establishment of graphical monitoring grafana
自动化运维利器ansible基础
The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
全网最全tcpdump和Wireshark抓包实践
sql语句优化,order by desc速度优化
网络分层概念及基本知识
Solrcloud related commands
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
03 products and promotion developed by individuals - plan service configurator v3.0
传统家装有落差,VR全景家装让你体验新房落成效果
connection reset by peer