Skip to content

Commit

Permalink
Merge pull request #87 from rsksmart/fix/remove-Db-file-and-export-ob…
Browse files Browse the repository at this point in the history
…ject-with-prisma-client

fix: create and export a single centralized prismaClient object instead of going through Db.js file
  • Loading branch information
nicov-iov authored Aug 19, 2023
2 parents af2fe62 + f1e66f1 commit d2201ee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/api/lib/getActiveAccounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prismaClient } from '../../lib/Db'
import { prismaClient } from '../../lib/prismaClient'

export default async function getActiveAccounts () {
const query = {
Expand Down
44 changes: 0 additions & 44 deletions src/lib/Db.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/lib/prismaClient.js
Original file line number Diff line number Diff line change
@@ -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 }
2 changes: 1 addition & 1 deletion src/repositories/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit d2201ee

Please sign in to comment.