1const boostrap = pool => {
2 app.use((req, res, next) => {
3 pool
4 .acquire()
5 .then(session => {
6 res.locals.db = session;
7 res.on('end', () => {
8 console.log('end : closing db session...');
9 if (session) {
10 session.close();
11 session = null;
12 };
13 });
14 res.on('close', () => {
15 console.log('close : closing db session...');
16 if (session) {
17 session.close();
18 session = null;
19 };
20 });
21 res.on('finish', () => {
22 console.log('finish : closing db session...');
23 if (session) {
24 session.close();
25 session = null;
26 };
27 });
28 next();
29 })
30 .catch(err => {
31 console.log('err : closing db session...');
32 if (session) {
33 session.close();
34 session = null;
35 };
36 res.status(500).send(err);
37 });
38 });
39
40
1const client = new OrientDBClient({
2 host: "odbhost",
3 db: "userDBName",
4 user: "userId",
5 password: "userPassword",
6 rootUser: "rootId",
7 rootPassword: "rootPassword",
8 pool: {
9 max: 200
10 },
11 logger: { debug: console.log.bind(null,"OrientDB: ") }
12});
13
14... bunch of stuff here, then :
15
16
17 client
18 .connect()
19 .then(() => {
20 return client.sessions({
21 name: "userDBName",
22 user: "userId",
23 password: "userPassword",
24 rootUser: "rootId",
25 rootPassword: "rootPassword",
26 pool: {
27 max: 25
28 },
29 logger: { debug: console.log.bind(null,"OrientDB: ") }
30 });
31 })
32 .then(pool => {
33 console.log('loading bootstrap pool ...')
34 boostrap(pool);
35 })
36 .catch(err => {
37 console.log(err);
38 });
39