Skip to content

Instantly share code, notes, and snippets.

@wolf4ood
Created April 24, 2019 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolf4ood/c3c00bc3e782069c70d726a00bb29a8f to your computer and use it in GitHub Desktop.
Save wolf4ood/c3c00bc3e782069c70d726a00bb29a8f to your computer and use it in GitHub Desktop.
OrientJS pipe exsample
const OrientDBClient = require("orientjs").OrientDBClient;
const fs = require("fs");
const { Transform } = require("stream");
const dbConnectionData = {
host: "localhost",
port: 2424
};
const dbData = {
username: "admin",
password: "admin",
name: "demodb"
};
const writeStream = (session, path, query) => {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(path);
let counter = 0;
let transform = new Transform({
objectMode: true,
transform(transaction, encoding, callback) {
callback(null, JSON.stringify(transaction));
}
});
session
.query(query)
.on("data", () => counter++)
.pipe(transform)
.pipe(file);
file.on("finish", () => {
resolve(counter);
});
});
};
(async () => {
const client = await OrientDBClient.connect(dbConnectionData);
const session = await client.session(dbData);
const results = await writeStream(session, "big.json", "select from V");
await session.close();
await client.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment