mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
* define ids and slugs in categories, check for existing ids, only seed the new ids * seed categories respecting existing categories --------- Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { getDriver, getNeode } from '@db/neo4j'
|
|
|
|
import type { Driver } from 'neo4j-driver'
|
|
|
|
export const query =
|
|
(driver: Driver) =>
|
|
async ({ query, variables = {} }: { query: string; variables?: object }) => {
|
|
const session = driver.session()
|
|
|
|
const result = session.readTransaction(async (transaction) => {
|
|
const response = await transaction.run(query, variables)
|
|
return response
|
|
})
|
|
|
|
try {
|
|
return await result
|
|
} finally {
|
|
await session.close()
|
|
}
|
|
}
|
|
|
|
export const write =
|
|
(driver: Driver) =>
|
|
async ({ query, variables = {} }: { query: string; variables?: object }) => {
|
|
const session = driver.session()
|
|
|
|
const result = session.writeTransaction(async (transaction) => {
|
|
const response = await transaction.run(query, variables)
|
|
return response
|
|
})
|
|
|
|
try {
|
|
return await result
|
|
} finally {
|
|
await session.close()
|
|
}
|
|
}
|
|
|
|
export default () => {
|
|
const driver = getDriver()
|
|
const neode = getNeode()
|
|
|
|
return {
|
|
driver,
|
|
neode,
|
|
query: query(driver),
|
|
write: write(driver),
|
|
}
|
|
}
|