-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose config
as a public property
#153
Conversation
__tests__/index.test.ts
Outdated
test('exposes database url', async () => { | ||
const connection = connect(config) | ||
expect(connection.connectionUrl).toBe('https://example.com/') | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the driver the connection URL is always https
and naming the function connectionUrl
might not be 100% accurate.
All we might need here is a get configUrl () { return config.url }
or make config
public.
For context is this a convenience method so you don't have to pass the database URL through PrismaPlanetScale
and/or PrismaClient
?
import { Client } from '@planetscale/database'
import { PrismaPlanetScale } from '@prisma/adapter-planetscale'
import { PrismaClient } from '@prisma/client'
import dotenv from 'dotenv'
import { fetch as undiciFetch } from 'undici'
dotenv.config()
const connectionString = `${process.env.DATABASE_URL}`
const client = new Client({ url: connectionString, fetch: undiciFetch })
const adapter = new PrismaPlanetScale(client)
const prisma = new PrismaClient({ adapter })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
For driver adapters, we decided to leave configuration of a DB client to the user. That means that Client
is already configured by the time any of our code is executed. At the same time, we need some information from the connection string to build our SQL queries: in MySQL case, this is the database name. We really don't want to require our users to supply it twice, and using different DB name than the one specified in the connection string does not make sense in our world. So, if it is already part of the connection string, it makes a perfect sense to take it from there.
In Prisma's driver adapter for Planetscale, we need to be able to get database name from the connection string. Currently, url is not exposed as a public property. In this PR we add such a property, `connectionUrl` to both ``Client` and `Connection` classes. Unlike existing private `url` property, this one is more or less unchainged from what user have passed in a config.
Co-authored-by: Ayrton <ayrton.decraene@gmail.com>
dd84460
to
4ce7f65
Compare
config
as a public property
In Prisma's driver adapter for Planetscale, we need to be able to get database name from the connection string. Currently, url is not exposed as a public property. In this PR we solve this by exposing
config
object that we get from user through constructor.