{"id":20935436,"url":"https://github.com/ww-tech/graph-sync","last_synced_at":"2025-10-08T05:33:00.317Z","repository":{"id":47365227,"uuid":"381069648","full_name":"ww-tech/graph-sync","owner":"ww-tech","description":"Keep PostgreSQL and Neo4j in sync using Kafka Connector.","archived":false,"fork":false,"pushed_at":"2021-09-02T04:56:03.000Z","size":148,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-10T09:46:05.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ww-tech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-28T14:57:51.000Z","updated_at":"2025-04-09T20:49:59.000Z","dependencies_parsed_at":"2022-09-22T15:40:37.850Z","dependency_job_id":null,"html_url":"https://github.com/ww-tech/graph-sync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ww-tech/graph-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ww-tech%2Fgraph-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ww-tech%2Fgraph-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ww-tech%2Fgraph-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ww-tech%2Fgraph-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ww-tech","download_url":"https://codeload.github.com/ww-tech/graph-sync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ww-tech%2Fgraph-sync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278892284,"owners_count":26063967,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-18T22:14:56.528Z","updated_at":"2025-10-08T05:33:00.267Z","avatar_url":"https://github.com/ww-tech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphSync\n\nKeep PostgreSQL and Neo4j in sync using Kafka Connector.\n\n## Usage\n\n#### `new GraphSync(options)` - Create a GraphSync instance\n- `options` {Object}\n  - `pgPool` {Pool} postgres client (must have `connect()` method)\n  - `neo4jClient` {GraphDatabase} neo4j client (must have `cypher()` method)\n  - `kafkaConsumer` {Consumer} kafka consumer (must have `run()` method)\n\n#### `registerTable(options)` - Configure mapping between rows and nodes\n- `options` {Object}\n  - `tableName` {String} the name of the table\n  - `getLabels` {Function} returns the labels for the node\n  - `getProperties` {Function} returns the properties for the node\n  - `getRelationships` {Function} returns the relationships for the node\n\n#### `generateNode(options)` - Get cypher query for creating a node\n- `options` {Object}\n  - `tableName` {String} the name of the table\n  - `row` {Object} the relational row data\n- Returns {String} cypher query to create node\n\n#### `generateRelationships(options)` - Get cypher query for creating relationships\n- `options` {Object}\n  - `tableName` {String} the name of the table\n  - `row` {Object} the relational row data\n- Returns {String} cypher query to create relationships\n\n#### `initialLoad()` - Read all relational rows and write all graph nodes and relationships\n\n#### `listen()` - Listen for messages on the Kafka topic and update the graph\n\n## Example\n\n### 1. Define the relational schema with foreign keys\n\n```sql\nCREATE TABLE cuisine (\n  id uuid,\n  name text\n)\n\nCREATE TABLE foods (\n  id uuid,\n  name text,\n  metadata jsonb\n)\n\nCREATE TABLE recipes (\n  id uuid,\n  name text,\n  cuisine_id uuid,\n  CONSTRAINT cuisine FOREIGN KEY (cuisine_id) REFERENCES cuisines (id)\n)\n\nCREATE TABLE ingredients (\n  recipe_id uuid,\n  food_id uuid,\n  CONSTRAINT recipe FOREIGN KEY (recipe_id) REFERENCES recipes (id),\n  CONSTRAINT food FOREIGN KEY (food_id) REFERENCES foods (id)\n)\n```\n\n### 2. Instantiate Graph Sync\n\n```js\nimport GraphSync from 'graph-sync'\nimport pg from 'pg'\nimport neo4j from 'neo4j-driver'\nimport Kafka from 'kafka'\n\nconst pgPool = new pg.Pool()\nconst neo4jDriver = neo4j.driver()\nconst kafka = new Kafka()\nconst kafkaConsumer = kafka.consumer()\nconst graphSync = new GraphSync({ pgPool, neo4jDriver, kafkaConsumer })\n```\n\n### 3. Define the nodes, labels, properties and relationships for the graph\n\n```js\n// Specify the relational table and corresponding label for the graph.\nawait graphSync.registerTable({\n  tableName: 'cuisines',\n  getLabels: () =\u003e ['Cuisine']\n})\n\n// By default, all relational columns (except foreign keys) are saved\n// as properties for the nodes in the graph. You can transform the\n// data if you want different custom properties in the graph.\nawait graphSync.registerTable({\n  tableName: 'foods',\n  getLabels: row =\u003e row.isBeverage ? ['Beverage'] : ['Food'],\n  getProperties: row =\u003e ({ ...row, myCustomProperty: 123 })\n})\n\n// You can create one-to-many relationships between \"this\" node and \n// another node using the name of the foreign key constraint.\nawait graphSync.registerTable({\n  tableName: 'recipes',\n  getLabels: () =\u003e ['Recipe'],\n  getRelationships: row =\u003e ['(this)-[:HAS_CUISINE]-\u003e(cuisine)']\n})\n\n// You can create many-to-many relationships between foreign keys.\n// We've omitted a label, so it will not create a node on the graph.\nawait graphSync.registerTable({\n  tableName: 'ingredients',\n  getRelationships: row =\u003e ['(recipe)-[:HAS_INGREDIENT]-\u003e(food)']\n})\n```\n\n### 4. Create the graph and/or keep it in sync\n\n```js\n// Generate the graph and sync it to Neo4j\nawait graphSync.initialLoad()\n\n// Subscribe to the Kafka topic and update the graph\ngraphSync.listen()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fww-tech%2Fgraph-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fww-tech%2Fgraph-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fww-tech%2Fgraph-sync/lists"}