Thêm khả năng kết nối cơ sở dữ liệu với ứng dụng Express chỉ là vấn đề tải một Nút thích hợp. js cho cơ sở dữ liệu trong ứng dụng của bạn. Tài liệu này giải thích ngắn gọn cách thêm và sử dụng một số Nút phổ biến nhất. js cho các hệ thống cơ sở dữ liệu trong ứng dụng Express của bạn Các trình điều khiển cơ sở dữ liệu này nằm trong số nhiều trình điều khiển có sẵn. Đối với các tùy chọn khác, hãy tìm kiếm trên trang web npm Cassandramô-đun. trình điều khiển cassandra Cài đặt$ npm install cassandra-driver
Thí dụconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
Đế đi văngmô-đun. đi văng Cài đặt$ npm install couchbase
Thí dụconst couchbase = require('couchbase')
const bucket = (new couchbase.Cluster('http://localhost:8091')).openBucket('bucketName')
// add a document to a bucket
bucket.insert('document-key', { name: 'Matt', shoeSize: 13 }, (err, result) => {
if (err) {
console.log(err)
} else {
console.log(result)
}
})
// get all documents with shoe size 13
const n1ql = 'SELECT d.* FROM `bucketName` d WHERE shoeSize = $1'
const query = N1qlQuery.fromString(n1ql)
bucket.query(query, [13], (err, result) => {
if (err) {
console.log(err)
} else {
console.log(result)
}
})
Đi văngDBmô-đun. nano Cài đặt$ npm install nano
Thí dụconst nano = require('nano')('http://localhost:5984')
nano.db.create('books')
const books = nano.db.use('books')
// Insert a book document in the books database
books.insert({ name: 'The Art of war' }, null, (err, body) => {
if (err) {
console.log(err)
} else {
console.log(body)
}
})
// Get a list of all books
books.list((err, body) => {
if (err) {
console.log(err)
} else {
console.log(body.rows)
}
})
cấp độDBmô-đun. lên cấp Cài đặt$ npm install level levelup leveldown
Thí dụconst levelup = require('levelup')
const db = levelup('./mydb')
db.put('name', 'LevelUP', (err) => {
if (err) return console.log('Ooops!', err)
db.get('name', (err, value) => {
if (err) return console.log('Ooops!', err)
console.log(`name=${value}`)
})
})
mysqlmô-đun. mysql Cài đặt________số 8_______Thí dụconst mysql = require('mysql')
const connection = mysql.createConnection({
host: 'localhost',
user: 'dbuser',
password: 's3kreee7',
database: 'my_db'
})
connection.connect()
connection.query('SELECT 1 + 1 AS solution', (err, rows, fields) => {
if (err) throw err
console.log('The solution is: ', rows[0].solution)
})
connection.end()
MongoDBmô-đun. mongodb Cài đặtconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
0Ví dụ (v2. *)const cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
1Ví dụ (v3. *)const cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
2Nếu bạn muốn có trình điều khiển mô hình đối tượng cho MongoDB, hãy xem Mongoose neo4jmô-đun. trình điều khiển neo4j Cài đặtconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
3Thí dụconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
4tiên trimô-đun. oracledb Cài đặtGHI CHÚ. const cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
5Thí dụconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
6PostgreSQLmô-đun. pg-hứa Cài đặtconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
7Thí dụconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
8làm lạimô-đun. làm lại Cài đặtconst cassandra = require('cassandra-driver')
const client = new cassandra.Client({ contactPoints: ['localhost'] })
client.execute('select key from system.local', (err, result) => {
if (err) throw err
console.log(result.rows[0])
})
9Thí dụ$ npm install couchbase
0Máy chủ SQLmô-đun. tẻ nhạt Cài đặt$ npm install couchbase
1Thí dụ$ npm install couchbase
2SQLitemô-đun. sqlite3 Cài đặt$ npm install couchbase
3Thí dụ$ npm install couchbase
4Elaticsearchmô-đun. tìm kiếm đàn hồi Cài đặt$ npm install couchbase
5Thí dụ$ npm install couchbase
6 |