Skip to content
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

Merged
merged 3 commits into from
Dec 18, 2023

Conversation

SevInf
Copy link
Contributor

@SevInf SevInf commented Dec 12, 2023

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.

@ayrton ayrton requested a review from iheanyi December 13, 2023 11:26
Comment on lines 65 to 70
test('exposes database url', async () => {
const connection = connect(config)
expect(connection.connectionUrl).toBe('https://example.com/')
})
Copy link
Contributor

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 })

Copy link
Contributor Author

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.

Sergey Tatarintsev and others added 3 commits December 18, 2023 17:09
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>
@SevInf SevInf force-pushed the fix/expose-conn-url branch from dd84460 to 4ce7f65 Compare December 18, 2023 16:21
@SevInf SevInf changed the title Expose connection URL as a public property Expose config as a public property Dec 18, 2023
@ayrton ayrton merged commit b4bdee0 into planetscale:main Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants