-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase Integration
More file actions
23 lines (22 loc) · 879 Bytes
/
Copy pathDatabase Integration
File metadata and controls
23 lines (22 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1.) Database Intgeration Packages:
To connect to any type of database, there are a set of drivers provided.
Eg:
With Cassandra;
npm install --save cassandra-driver
Then;
const driver = require('cassandra-driver');
const client = new driver.Client({contactPoints: ['localhost'],
keyspace: 'test',
localDataCenter: 'datacenter1'});
const listEmployees = (res)=>{
var rows = 0;
client.execute('select * from test.employee').then((resultSet)=>{
console.log(resultSet.rowLength);
rows = resultSet.rowLength;
res.end("Count = " + rows);
}).catch((err)=>{
console.log('Error on listing from database' + err);
});
}
Now, from api, call listEployees(res);
This will return the count(employee) in table employee.