{"id":13630887,"url":"https://github.com/orientechnologies/orientjs","last_synced_at":"2025-04-17T17:32:02.769Z","repository":{"id":16283021,"uuid":"19031487","full_name":"orientechnologies/orientjs","owner":"orientechnologies","description":"The official fast, lightweight node.js client for OrientDB","archived":false,"fork":false,"pushed_at":"2023-11-08T10:37:32.000Z","size":2273,"stargazers_count":327,"open_issues_count":145,"forks_count":67,"subscribers_count":33,"default_branch":"develop","last_synced_at":"2025-04-16T06:10:32.593Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://orientdb.dev","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orientechnologies.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-04-22T13:54:27.000Z","updated_at":"2025-04-10T22:01:22.000Z","dependencies_parsed_at":"2023-01-13T18:46:43.036Z","dependency_job_id":"8d0632f1-cc97-4825-9594-3b1be0da50c9","html_url":"https://github.com/orientechnologies/orientjs","commit_stats":{"total_commits":1309,"total_committers":60,"mean_commits":"21.816666666666666","dds":0.7104660045836517,"last_synced_commit":"7b873d60fedf3a42164d2aded7d7860bca2bf47c"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orientechnologies%2Forientjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orientechnologies%2Forientjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orientechnologies%2Forientjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orientechnologies%2Forientjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orientechnologies","download_url":"https://codeload.github.com/orientechnologies/orientjs/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249360037,"owners_count":21257159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T22:02:02.124Z","updated_at":"2025-04-17T17:32:01.926Z","avatar_url":"https://github.com/orientechnologies.png","language":"JavaScript","readme":"# OrientJS driver\n\nOfficial [orientdb](http://www.orientechnologies.com/orientdb/) driver for node.js. Fast, lightweight, uses the binary protocol.\n[![REUSE status](https://api.reuse.software/badge/github.com/orientechnologies/orientjs)](https://api.reuse.software/info/github.com/orientechnologies/orientjs)\n[![npm version](https://img.shields.io/npm/v/orientjs.svg?style=flat-square)](https://www.npmjs.com/package/orientjs)\n[![npm downloads](https://img.shields.io/npm/dm/orientjs.svg?style=flat-square)](https://www.npmjs.com/package/orientjs)\n\nNOTE: _Release v3.0 provides new APIs in order to support OrientDB 3.0 features_.\n\n# Features\n\n- Tested with latest OrientDB (2.2.x and 3.0.x).\n- Intuitive API, based on [bluebird](https://github.com/petkaantonov/bluebird) promises.\n- Fast binary protocol parser.\n- Streaming Support\n- Stateful Transaction Support\n- Distributed Support\n- Access multiple databases via the same socket (Session Pooling).\n- Connection Pooling\n- Migration support.\n- Simple CLI.\n\n\n# Versions and Compatibility\n\nOrientJS v3.0 contains backwards compatible APIs for OrientDB 2.2.x and OrientDB 3.0.x using the old protocol version 33 ([Legacy](http://orientdb.com/docs/last/orientjs/OrientJS-Legacy.html)). New APIs are shipped in v3.0 to support the new protocol featuring Streaming, Stateful transactions, new SQL engine etc..\n\n\n# Resources\n\n\n- [Documentation](https://orientdb.com/docs/last/OrientJS.html)\n\u003c!--- [API Docs](http://orientdb.com/docs/last/orientjs/OrientJS.html)--\u003e\n- [Example Projects](https://github.com/orientechnologies/orientjs-example)\n\n\n# Installation\n\nInstall via npm.\n\n```sh\nnpm install orientjs\n```\nFor Typescript usage :\n\n```sh\nnpm install @types/orientjs\n```\n\n# Quick Start\n\n## Connect to OrientDB\n\nUse the `connect` function in order to create a new `OrientDBClient` instance.\n\n```js\nconst OrientDBClient = require(\"orientjs\").OrientDBClient;\n\nOrientDBClient.connect({\n  host: \"localhost\",\n  port: 2424\n}).then(client =\u003e {\n  return client.close();\n}).then(()=\u003e {\n   console.log(\"Client closed\");\n});\n```\n\n\n\n### Single Session\n\nTo open a new standalone session use the `client.session` api. This api will create a new stateful session associated with the given database and credentials. Once done, call `session.close` in order to release the session on the server. Session are stateful since OrientJS 3.0 as they can execute server side transactions.\n\n\n```js\nclient.session({ name: \"demodb\", username: \"admin\", password: \"admin\" })\n.then(session =\u003e {\n\t// use the session\n\t... \n\t// close the session\n\treturn session.close();\n});\n```\n\n\n\n### Pooled Sessions\n\nOpening and closing sessions everytime can be expensive, since open and close require a network request to the server. Use the API `client.sessions` to create a pool of sessions with a given database and credentials. To get a session from the pool call the api `pool.acquire`. Once done with the session you can return the session to the pool by calling `session.close`\n\n\n```js\n// Create a sessions Pool\nclient.sessions({ name: \"demodb\", username: \"admin\", password: \"admin\", pool: { max: 10} })\n  .then(pool =\u003e {\n    // acquire a session\n    return pool.acquire()\n      .then(session =\u003e {\n        // use the session\n        ...\n        // release the session\n        return session.close();\n      })\n      .then(() =\u003e {\n      \t // close the pool\n        return pool.close();\n      });\n  });\n});\n```\n\n## Session API\n\nOnce obtained a session using the above APIs you can:\n\n- Run a Query (Idempotent SQL statement)\n- Run a Command (Idempotent or non idempotent SQL statement)\n- Run a Transaction\n- Run a live query\n\n\n### Query\n\n\nStreaming\n\n```js\nsession.query(\"select from OUser where name = :name\", {params: { name: \"admin\" }})\n.on(\"data\", data =\u003e {\n\tconsole.log(data);\n})\n.on('error',(err)=\u003e {\n  console.log(err);\n})\n.on(\"end\", () =\u003e {\n\tconsole.log(\"End of the stream\");\n});\n```\n\n\nor use `.all` API that convert the stream to a Promise and collect the result set into an array\n\n```js\nsession.query(\"select from OUser where name = :name\", { params : {name: \"admin\" }})\n.all()\n.then((results)=\u003e {\n\tconsole.log(results);\n});\n```\n\n### Command\n\n```js\nsession.command(\"insert into V set name = :name\", {params: { name: \"test\" }})\n.all()\n.then(result =\u003e {\n\tconsole.log(result);\n});\n```\n\n### Transaction\n\nUse the api session.runInTransaction in order to run a unit of work in a managed transaction (begin/commit/retry)\n\n```js\nsession.runInTransaction((tx)=\u003e{\n\treturn tx.command(\"insert into V set name = :name\", {params: { name: \"test\" }}).all()\n}).then(({result,tx}) =\u003e {\n\tconsole.log(result);\n\tconsole.log(tx);\n});\n```\n\n### Live Queries\n\n\n```js\nsession.liveQuery(\"select from V\").on(\"data\", data =\u003e {\n\tconsole.log(data);\n});\n```\n\n# Running Tests\n\nTo run the test suite, first invoke the following command within the repo, installing the development dependencies:\n\n```sh\nnpm install\n```\n\nThen run the tests:\n\n```sh\nnpm test\n```\n\n\t\n## History\n\nIn 2012, [Gabriel Petrovay](https://github.com/gabipetrovay) created the original [node-orientdb](https://github.com/gabipetrovay/node-orientdb) library, with a straightforward callback based API.\n\nIn early 2014, [Giraldo Rosales](https://github.com/nitrog7) made a [whole host of improvements](https://github.com/nitrog7/node-orientdb), including support for orientdb 1.7 and switched to a promise based API.\n\nLater in 2014, codemix refactored the library to make it easier to extend and maintain, and introduced an API similar to [nano](https://github.com/dscape/nano). The result is so different from the original codebase that it warranted its own name and npm package. This also gave us the opportunity to switch to semantic versioning.\n\nIn June 2015, Orient Technologies company officially adopted the Oriento driver and renamed it as OrientJS.\n\n### Notes for contributors\n\nPlease see [CONTRIBUTING](./CONTRIBUTING.md).\n\n### Building from the Source Code\n\nWhen building from source code, you need to download the driver directly from [GitHub](https://github.com/orientechnologies/orientjs), then run NPM against the branch you want to use or test.\n\n1. Using Git, clone the package repository, then enter the new directory:\n\n   \u003cpre\u003e\n   $ \u003ccode class=\"lang-sh userinput\"\u003egit clone https://github.com/orientechnologies/orientjs.git\u003c/code\u003e\n   $ \u003ccode class=\"lang-sh userinput\"\u003ecd orientjs\u003c/code\u003e\n   \u003c/pre\u003e\n\n2. When you clone the repository, Git automatically provides you with the current state of the `master` branch.  If you would like to work with another branch, like `develop` or test features on past releases, you need to check out the branch you want.  For instance,\n\n   \u003cpre\u003e\n   $ \u003ccode class=\"lang-sh userinput\"\u003egit checkout develop\u003c/code\u003e\n   \u003c/pre\u003e\n\n3. Once you've selected the branch you want to build, call NPM to handle the installation.\n\n   \u003cpre\u003e\n   $ \u003ccode class=\"lang-sh userinput\"\u003enpm install\u003c/code\u003e\n   \u003c/pre\u003e\n \n4. Run the tests to make sure it works:\n\n   \u003cpre\u003e\n   $ \u003ccode class=\"lang-sh userinput\"\u003enpm test\u003c/code\u003e\n   \u003c/pre\u003e\n\n\n### Changes\n\nSee [CHANGELOG](./CHANGELOG.md)\n\n\n\n### License\n\nApache 2.0 License, see [LICENSE](./LICENSE.md)\n\n","funding_links":[],"categories":["JavaScript","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forientechnologies%2Forientjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forientechnologies%2Forientjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forientechnologies%2Forientjs/lists"}