mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-04-02 15:45:32 +00:00
35 lines
934 B
TypeScript
35 lines
934 B
TypeScript
/* eslint-disable import-x/no-named-as-default-member */
|
|
import neo4j from 'neo4j-driver'
|
|
import Neode from 'neode'
|
|
|
|
import CONFIG from '@config/index'
|
|
import models from '@db/models/index'
|
|
|
|
import type { Driver } from 'neo4j-driver'
|
|
|
|
let driver: Driver
|
|
const defaultOptions = {
|
|
uri: CONFIG.NEO4J_URI,
|
|
username: CONFIG.NEO4J_USERNAME,
|
|
password: CONFIG.NEO4J_PASSWORD,
|
|
}
|
|
|
|
export function getDriver(options = {}) {
|
|
const { uri, username, password } = { ...defaultOptions, ...options }
|
|
if (!driver) {
|
|
driver = neo4j.driver(uri, neo4j.auth.basic(username, password))
|
|
}
|
|
return driver
|
|
}
|
|
|
|
let neodeInstance: Neode
|
|
export function getNeode(options = {}) {
|
|
if (!neodeInstance) {
|
|
const { uri, username, password } = { ...defaultOptions, ...options }
|
|
neodeInstance = new Neode(uri, username, password).with(models)
|
|
neodeInstance.extend('Post', 'Article', {})
|
|
return neodeInstance
|
|
}
|
|
return neodeInstance
|
|
}
|