Skip to content
Snippets Groups Projects
Commit accbdca0 authored by Timo Geissbühler's avatar Timo Geissbühler
Browse files

added db functionality

parent 6a8f8295
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^13.5.0",
"neo4j-driver": "^5.28.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-scripts": "5.0.1",
......@@ -5177,6 +5178,26 @@
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"license": "MIT"
},
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/batch": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz",
......@@ -5362,6 +5383,30 @@
"node-int64": "^0.4.0"
}
},
"node_modules/buffer": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT",
"dependencies": {
"base64-js": "^1.3.1",
"ieee754": "^1.2.1"
}
},
"node_modules/buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
......@@ -9162,6 +9207,26 @@
"node": ">=4"
}
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "BSD-3-Clause"
},
"node_modules/ignore": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
......@@ -11558,6 +11623,34 @@
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
"license": "MIT"
},
"node_modules/neo4j-driver": {
"version": "5.28.1",
"resolved": "https://registry.npmjs.org/neo4j-driver/-/neo4j-driver-5.28.1.tgz",
"integrity": "sha512-jbyBwyM0a3RLGcP43q3hIxPUPxA+1bE04RovOKdNAS42EtBMVCKcPSeOvWiHxgXp1ZFd0a8XqK+7LtguInOLUg==",
"license": "Apache-2.0",
"dependencies": {
"neo4j-driver-bolt-connection": "5.28.1",
"neo4j-driver-core": "5.28.1",
"rxjs": "^7.8.1"
}
},
"node_modules/neo4j-driver-bolt-connection": {
"version": "5.28.1",
"resolved": "https://registry.npmjs.org/neo4j-driver-bolt-connection/-/neo4j-driver-bolt-connection-5.28.1.tgz",
"integrity": "sha512-nY8GBhjOW7J0rDtpiyJn6kFdk2OiNVZZhZrO8//mwNXnf5VQJ6HqZQTDthH/9pEaX0Jvbastz1xU7ZL8xzqY0w==",
"license": "Apache-2.0",
"dependencies": {
"buffer": "^6.0.3",
"neo4j-driver-core": "5.28.1",
"string_decoder": "^1.3.0"
}
},
"node_modules/neo4j-driver-core": {
"version": "5.28.1",
"resolved": "https://registry.npmjs.org/neo4j-driver-core/-/neo4j-driver-core-5.28.1.tgz",
"integrity": "sha512-14vN8TlxC0JvJYfjWic5PwjsZ38loQLOKFTXwk4fWLTbCk6VhrhubB2Jsy9Rz+gM6PtTor4+6ClBEFDp1q/c8g==",
"license": "Apache-2.0"
},
"node_modules/no-case": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",
......@@ -14471,6 +14564,15 @@
"queue-microtask": "^1.2.2"
}
},
"node_modules/rxjs": {
"version": "7.8.2",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
"license": "Apache-2.0",
"dependencies": {
"tslib": "^2.1.0"
}
},
"node_modules/safe-array-concat": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.3.tgz",
......
......@@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^13.5.0",
"neo4j-driver": "^5.28.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-scripts": "5.0.1",
......
import logo from './logo.svg';
import './App.css';
import {getAllUsers} from './lib/db';
function App() {
const onClick = async () => {
const data = await getAllUsers()
console.log(data)
}
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<button onClick={onClick}>Get User</button>
</div>
);
}
......
import neo4j from 'neo4j-driver';
const uri = 'neo4j://localhost:7687'; // oder remote URI
const user = 'neo4j';
const password = 'sml12345';
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session({ database: 'learnlink' });
export const createUser = async (id, name, email, location) => {
const query = `CREATE (u:User {id: $id, name: $name, email: $email, location: $location}) RETURN u`;
return session.run(query, { id, name, email, location });
};
export const createCompany = async (id, name) => {
const query = `CREATE (c:Company {id: $id, name: $name}) RETURN c`;
return session.run(query, { id, name });
};
export const createJob = async (id, title, location) => {
const query = `CREATE (j:Job {id: $id, title: $title, location: $location}) RETURN j`;
return session.run(query, { id, title, location });
};
export const updateUser = async (id, email, location) => {
const query = `MATCH (u:User {id: $id}) SET u.email = $email, u.location = $location RETURN u`;
return session.run(query, { id, email, location });
};
export const updateCompany = async (id, name, industry) => {
const query = `MATCH (c:Company {id: $id}) SET c.name = $name, c.industry = $industry RETURN c`;
return session.run(query, { id, name, industry });
};
export const updateJob = async (id, title, location) => {
const query = `MATCH (j:Job {id: $id}) SET j.title = $title, j.location = $location RETURN j`;
return session.run(query, { id, title, location });
};
export const deleteUser = async (id) => {
const query = `MATCH (u:User {id: $id}) DETACH DELETE u`;
return session.run(query, { id });
};
export const deleteCompany = async (id) => {
const query = `MATCH (c:Company {id: $id}) DETACH DELETE c`;
return session.run(query, { id });
};
export const deleteJob = async (id) => {
const query = `MATCH (j:Job {id: $id}) DETACH DELETE j`;
return session.run(query, { id });
};
export const getUser = async (name) => {
const query = `MATCH (u:User {name: $name}) RETURN u`;
return session.run(query, { name });
};
export const getAllUsers = async () => {
const query = `MATCH (u:User) RETURN u`;
return session.run(query);
};
export const getUserRelationships = async (name) => {
const query = `MATCH (u:User {name: $name})-[r]-() RETURN r`;
return session.run(query, { name });
};
export const getUserCompany = async (name) => {
const query = `MATCH (u:User {name: $name})-[:WORKS_FOR]->(c:Company) RETURN c`;
return session.run(query, { name });
};
export const getRemoteJobs = async () => {
const query = `MATCH (j:Job) WHERE j.location = 'Remote' RETURN j`;
return session.run(query);
};
export const closeConnection = () => {
session.close();
driver.close();
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment