{"id":27376913,"url":"https://github.com/skaiworldwide-oss/agensgraph-nodejs","last_synced_at":"2025-10-14T01:35:06.921Z","repository":{"id":22221967,"uuid":"95638093","full_name":"skaiworldwide-oss/agensgraph-nodejs","owner":"skaiworldwide-oss","description":"A NodeJS driver for AgensGraph Multi-Model Database","archived":false,"fork":false,"pushed_at":"2025-03-24T02:00:04.000Z","size":596,"stargazers_count":12,"open_issues_count":5,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-13T12:57:37.541Z","etag":null,"topics":["genai","graphdb","multi-model-database","nosql","postgresql"],"latest_commit_sha":null,"homepage":"http://www.agensgraph.org/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skaiworldwide-oss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-28T06:49:14.000Z","updated_at":"2025-03-24T02:00:08.000Z","dependencies_parsed_at":"2025-03-24T02:23:55.708Z","dependency_job_id":"3c2b2f67-a112-4b40-8a6a-2da2dd7824aa","html_url":"https://github.com/skaiworldwide-oss/agensgraph-nodejs","commit_stats":null,"previous_names":["skaiworldwide-oss/agensgraph-nodejs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaiworldwide-oss%2Fagensgraph-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaiworldwide-oss%2Fagensgraph-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaiworldwide-oss%2Fagensgraph-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaiworldwide-oss%2Fagensgraph-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skaiworldwide-oss","download_url":"https://codeload.github.com/skaiworldwide-oss/agensgraph-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717261,"owners_count":21150389,"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":["genai","graphdb","multi-model-database","nosql","postgresql"],"created_at":"2025-04-13T12:57:43.032Z","updated_at":"2025-10-14T01:35:06.901Z","avatar_url":"https://github.com/skaiworldwide-oss.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AgensGraph client for Node.js\n\nhttps://www.npmjs.com/package/@skaiworldwide/ag-driver\n\nAgensGraph client for node.js. To be used concurrently with [node-postgres](https://github.com/brianc/node-postgres).\nAdds AgensGraph compatibility for node-postgres. Support for the Cypher query language, and vertex, edge and path graph\ndata types.\n\n## Usage\n\n### Install\n\n```sh\n# if you are using yarn\n$ yarn add pg @skaiworldwide/ag-driver\n\n# or npm\n$ npm install pg @skaiworldwide/ag-driver\n```\n\n## Connection\n\nTo connect to AgensGraph via node-js, one can connect via environment variables, programatically, or using a connection\nURI.\n\nConnecting programmatically can be done by passing an object with config values to your AgensGraph client and using\nclient.connect() to establish a connection:\n\n```js\nvar ag = require('@skaiworldwide/ag-driver');\nvar config = {\n    user: 'username',\n    password: 'password',\n    database: 'database name of agensgraph',\n    host: '127.0.0.1',\n    port: 5432\n};\n\nconst client = new ag.Client(config);\nclient.connect();\nclient.end();\n```\n\nUse client.end() to terminate the connection to the database. Calling client.end() without a callback function will\nreturn a promise.\n\n## Queries\n\nTo retrieve data from AgensGraph, use the query() API function to query the database. There are multiple ways to send\nqueries, including passing text directly, using parameters, passing in objects, and using prepared statements. The\nfollowing examples illustrate the different possible methods of querying.\n\nUsers can retrieve Cypher data by passing text directly to client.query():\n\n```js\nvar ag = require('@skaiworldwide/ag-driver');\nconst client = new ag.Client(Config);\n\nclient.connect();\nclient.query('SET graph_path = gpt'); //set graph path to gpt\nclient.query(\"MATCH (a:person)-[r:knows]-\u003e(b:person) WHERE b.name = 'Adam' RETURN a,r,b;\", function (err, res) {\n    if (err) {\n        throw err;\n    } else {\n        console.log(res.rows);\n    }\n});\nclient.end();\n```\n\nUsers can also send parameterized queries:\n\n```js\nconst text = \"MATCH (a:person)-[:knows]-\u003e(b:person) WHERE b.name = $1 RETURN a;\"\nconst values = ['Adam'];\n\nclient.connect();\nclient.query('SET graph_path = gpt'); //set graph path to gpt\nclient.query(text, values, function (err, res) {\n    if (err) {\n        throw err;\n    } else {\n        console.log(res.rows);\n    }\n});\n```\n\nPassing a config object:\n\n```js\nconst query = {\n    text: \"MATCH (a:person)-[:knows]-\u003e(b:person) WHERE b.name = $1 RETURN a;\",\n    values: ['Adam']\n}\n\nclient.connect();\nclient.query('SET graph_path = gpt'); //set graph path to gpt\nclient.query(query, function (err, res) {\n    if (err) {\n        throw err;\n    } else {\n        console.log(res.rows);\n    }\n});\n```\n\nUsers can also use named prepared statements. Using prepared statements allows query execution plans to be cached on the\nserver on a per connection statement. Once a query name is sent to the server, it will be parsed and executed. On\nsubsequent sends the query will skip the parse request and instead send the name of the query:\n\n```js\nconst query = {\n    name: 'fetch-data',\n    text: \"MATCH(n) WHERE n.name = 'Eve' RETURN n\"\n}\n\nclient.query(query, (err, res) =\u003e {\n    if (err) {\n        throw err;\n    } else {\n        console.log(res.rows);\n    }\n});\n\n```\n\n## Creating Data\n\nTo create data in AgensGraph, the query() API function is again used to query the database. Below is an example of\ncreating Cypher data by passing text directly to client.query():\n\n```js\nvar ag = require('@skaiworldwide/ag-driver');\nconst client = new ag.Client(Config);\n\nclient.connect();\nclient.query('CREATE GRAPH gpt');\nclient.query('SET graph_path = gpt');\nclient.query(\"CREATE (a:person {name:'Alice'})-[r:knows {from: 'school'}]-\u003e(b:person {name: 'Bob'}) RETURN a,r,b\", function (err, res) {\n    if (err) {\n        throw err;\n    } else {\n        a = res.rows[0].a;\n        r = res.rows[0].r;\n        b = res.rows[0].b;\n        console.log(a.label);\n        console.log(a.id);\n        console.log(a.props.name);\n\n        console.log(r.label);\n        console.log(r.id);\n        console.log(r.startVertexId);\n        console.log(r.endVertexID);\n        console.log(r.props.from);\n\n        console.log(b.label);\n        console.log(b.id);\n        console.log(b.props.name);\n    }\n});\n\n```\n\n## Graph Data Types\n\nThe following is a brief explanation detailing the different datatypes handled by agensgraph-nodejs extension.\n\n| Class Function    | Description     | Properties      |\n| ------------------| --------------- | --------------- |\n| `GraphId`    | Corresponds to the `graphid` type in AgensGraph. | oid, id\n| `Vertex`     |Corresponds to `vertex` type in AgensGraph. It supports access methods for the label and properties. | label, id, props\n| `Edge`       | Corresponds to `edge` type in AgensGraph. It supports access methods for the label and properties. | label, id, start, end, props\n| `Path`       | Corresponds to `graphpath` type in AgensGraph. It supports access methods for the length of the path, and accessing for vertexes and edges in the path. | vertices, edges, start, end, len\n\n## Related projects\n\n- **drivine**\n    - Graph database driver for Node.js and TypeScript implemented on top of the NestJS platform.\n    - https://github.com/liberation-data/drivine\n    - https://drivine.org/\n\n## TODO\n\n- Typescript Refactoring\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskaiworldwide-oss%2Fagensgraph-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskaiworldwide-oss%2Fagensgraph-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskaiworldwide-oss%2Fagensgraph-nodejs/lists"}