diff --git a/src/api/lib/getActiveAccounts.js b/src/api/lib/getActiveAccounts.js index d6eb82cc..67c5394a 100644 --- a/src/api/lib/getActiveAccounts.js +++ b/src/api/lib/getActiveAccounts.js @@ -1,4 +1,4 @@ -import { prismaClient } from '../../lib/Db' +import { prismaClient } from '../../lib/prismaClient' export default async function getActiveAccounts () { const query = { diff --git a/src/lib/Db.js b/src/lib/Db.js deleted file mode 100644 index 9d84574f..00000000 --- a/src/lib/Db.js +++ /dev/null @@ -1,44 +0,0 @@ -import { PrismaClient } from '@prisma/client' -import { config } from './config' - -const { - protocol, - host, - port, - databaseName, - user, - password -} = config.db - -class Db { - constructor () { - this.protocol = protocol - this.host = host - this.port = port - this.databaseName = databaseName - this.user = user - this.password = password - - if (user && password) { - this.url = `${protocol}${user}:${password}@${host}:${port}/${databaseName}` - } else { - this.url = `${protocol}@${host}:${port}/${databaseName}` - } - - this.prismaClient = new PrismaClient({ - datasources: { - db: { - url: this.url - } - }, - // log: ['query', 'info', 'warn', 'error'], - errorFormat: 'pretty' - }) - } - - getClient () { - return this.prismaClient - } -} - -export const prismaClient = (new Db()).getClient() diff --git a/src/lib/prismaClient.js b/src/lib/prismaClient.js new file mode 100644 index 00000000..26408f07 --- /dev/null +++ b/src/lib/prismaClient.js @@ -0,0 +1,25 @@ +import { PrismaClient } from '@prisma/client' +import { config } from './config' + +const { + protocol, + host, + port, + databaseName, + user, + password +} = config.db + +if (!user || !password) throw new Error('Missing database credentials in src/lib/defaultConfig.js') + +const prismaClient = new PrismaClient({ + datasources: { + db: { + url: `${protocol}${user}:${password}@${host}:${port}/${databaseName}` + } + }, + // log: ['query', 'info', 'warn', 'error'], + errorFormat: 'pretty' +}) + +export { prismaClient } diff --git a/src/repositories/index.js b/src/repositories/index.js index 723e90e6..1760d053 100644 --- a/src/repositories/index.js +++ b/src/repositories/index.js @@ -1,4 +1,4 @@ -import { prismaClient } from '../lib/Db' +import { prismaClient } from '../lib/prismaClient' import { getAddressRepository } from './address.repository' import { getBalancesRepository } from './balances.repository' import { getBlocksRepository } from './blocks.repository'