Skip to content

feature(raw): Improve prisma.raw by re-exporting all of sql-template-tag#2311

Merged
timsuchanek merged 3 commits intoprisma:masterfrom
zachasme:improved-raw
May 25, 2020
Merged

feature(raw): Improve prisma.raw by re-exporting all of sql-template-tag#2311
timsuchanek merged 3 commits intoprisma:masterfrom
zachasme:improved-raw

Conversation

@zachasme
Copy link
Copy Markdown
Contributor

When sending raw queries using prisma.raw it would be nice to have access to all of sql-template-tag.

We had a specific query where we wanted to write the SQL by hand. But the current API is quite limited. Nesting and joining in particular from sql-template-tag are very useful when composing complex queries.

This PR simply re-exports the same API as a direct import, adds a case for prisma.sql input to prisma.raw, and adds a simple test as well.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 27, 2020

CLA assistant check
All committers have signed the CLA.

@Sytten
Copy link
Copy Markdown
Contributor

Sytten commented Apr 27, 2020

I also happen to need this! Did you manage to get some SQL syntax highlight at the same time? This is something that I would like to see improved in the vscode plugin.

Comment thread src/packages/client/src/runtime/getPrismaClient.ts Outdated
Comment thread src/packages/client/src/runtime/getPrismaClient.ts Outdated
@zachasme
Copy link
Copy Markdown
Contributor Author

zachasme commented May 11, 2020

Thanks for the feedback, I've rebased on master, moved the exports to the module directly (instead of prisma instance) and added exports to TSClient.ts.

Comment thread src/packages/client/src/runtime/getPrismaClient.ts
query = stringOrTemplateStringsArray[sqlOutput]
parameters = {
values: JSON.stringify(stringOrTemplateStringsArray.values),
__prismaRawParamaters__: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, which part? :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paramaters -> Parameters

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is the actual name used in the codebase.

if (obj.values && obj.__prismaRawParamaters__) {

You want this handled in another PR or this one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe another PR would be better. Getting this one merged and documented would be a big win, I really need it...
@timsuchanek @janpio

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate PR sounds better, indeed.

@janpio janpio requested a review from timsuchanek May 14, 2020 18:31
@zachasme
Copy link
Copy Markdown
Contributor Author

What else can I do to move this along?

@pantharshit00 pantharshit00 requested a review from Jolg42 May 15, 2020 12:12
@timsuchanek
Copy link
Copy Markdown
Contributor

@zachasme thanks, so far there's nothing needed from your side.
We first need to agree internally, if this is the API, that we want.
As soon as we've done so, we'll let you know here in the PR.

@janpio janpio changed the title Improve prisma.raw by re-exporting all of sql-template-tag feature(raw): Improve prisma.raw by re-exporting all of sql-template-tag May 23, 2020
@timsuchanek timsuchanek merged commit 9e7dff9 into prisma:master May 25, 2020
@timsuchanek
Copy link
Copy Markdown
Contributor

Thanks for the PR! I did a few changes about where to import stuff from, it's now building in our CI and will be available on alpha in 10 min.

@janpio janpio added this to the Beta 6 milestone May 25, 2020
@Sytten
Copy link
Copy Markdown
Contributor

Sytten commented May 26, 2020

Wow thanks a lot guys! Good job on landing this

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.

5 participants