Skip to content

Commit 6e5fe2a

Browse files
committed
Create RethinkDB example
1 parent 9c11989 commit 6e5fe2a

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
*.log
3+
node_modules/
4+
yarn.lock
5+
package-lock.json

rethinkdb/nodejs/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# RethinkDB client example
2+
3+
1. Clone the project: ``
4+
1. Open file `app.js` and update the configuration
5+
1. Install dependencies: `npm install`
6+
1. Run this example: `npm run start`

rethinkdb/nodejs/app.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const r = require('rethinkdbdash')({
2+
host: 'XXXXXX.stackhero-network.com', // This is the host you'll find on Stackhero console
3+
port: 29015,
4+
user: 'admin',
5+
password: 'XXXXXXXXXXXXX', // This is the admin password you've defined on Stackhero console
6+
ssl: true,
7+
silent: true
8+
});
9+
10+
(async () => {
11+
12+
console.log('Getting list of tables');
13+
const tables = await r.tableList();
14+
15+
if (tables.length) {
16+
console.log('The server has those tables: ' + tables.join());
17+
}
18+
19+
if (tables.indexOf('datasTest') === -1) {
20+
console.log('Creating table "datasTest"');
21+
await r.tableCreate('datasTest').run();
22+
}
23+
24+
console.log('Inserting datas into table datasTest');
25+
await r.table('datasTest')
26+
.insert({ test: 'ok' })
27+
.run();
28+
29+
console.log('Getting datas in table datasTest');
30+
const datas = await r.table('datasTest').run();
31+
console.log(datas);
32+
33+
console.log('Close connection');
34+
r.getPoolMaster().drain();
35+
36+
console.log('All done, your RethinkDB is up and running :)');
37+
})();
38+

rethinkdb/nodejs/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"scripts": {
3+
"start": "node app.js"
4+
},
5+
"dependencies": {
6+
"rethinkdbdash": "^2.3.31"
7+
}
8+
}

0 commit comments

Comments
 (0)