Skip to content

Commit

Permalink
fix(client): datasources - nest url instead of string
Browse files Browse the repository at this point in the history
Closes #2801
  • Loading branch information
timsuchanek committed Jun 19, 2020
1 parent d4c8517 commit ac7167a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ module.exports = async () => {
},
},
datasources: {
db: connectionString,
db: {
url: connectionString,
},
},
log: [
{
Expand Down
8 changes: 7 additions & 1 deletion src/packages/client/src/__tests__/types/blog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import {

// This file will not be executed, just compiled to check if the typings are valid
async function main() {
const prisma = new PrismaClient()
const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

prismaVersion.client

Expand Down
5 changes: 4 additions & 1 deletion src/packages/client/src/generation/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ exports.PrismaClient = PrismaClient`
* Client
**/
export declare type Datasource = {
url?: string
}
${new PrismaClientClass(
this.dmmf,
this.options.datasources,
Expand Down Expand Up @@ -381,7 +384,7 @@ class Datasources implements Generatable {
public toTS(): string {
const sources = this.internalDatasources
return `export type Datasources = {
${indent(sources.map((s) => `${s.name}?: string`).join('\n'), 2)}
${indent(sources.map((s) => `${s.name}?: Datasource`).join('\n'), 2)}
}`
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/packages/client/src/runtime/getPrismaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import { omit } from './utils/omit'

export type ErrorFormat = 'pretty' | 'colorless' | 'minimal'

export type Datasources = any
export type Datasource = {
url?: string
}
export type Datasources = Record<string, Datasource>

export interface PrismaClientOptions {
/**
Expand Down Expand Up @@ -173,9 +176,11 @@ export function getPrismaClient(config: GetPrismaClientOptions): any {
url: 'file:' + path.resolve(config.dirname, d.url),
}))

const inputDatasources = Object.entries(
options.datasources || {},
).map(([name, url]: any) => ({ name, url }))
const inputDatasources = Object.entries(options.datasources || {})
.filter(([_, source]) => {
return source && source.url
})
.map(([name, { url }]: any) => ({ name, url }))

const datasources = mergeBy(
predefinedDatasources,
Expand Down

0 comments on commit ac7167a

Please sign in to comment.