Skip to content

Commit

Permalink
chore(sdk): remove useless function databaseTypeToConnectorType (pris…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 authored and Andrew-Colman committed Aug 7, 2021
1 parent 04f0705 commit a69bff8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 40 deletions.
9 changes: 2 additions & 7 deletions packages/cli/src/Init.ts
Expand Up @@ -8,10 +8,7 @@ import {
link,
logger,
} from '@prisma/sdk'
import {
protocolToDatabaseType,
databaseTypeToConnectorType,
} from '@prisma/sdk/dist/convertCredentials'
import { protocolToConnectorType } from '@prisma/sdk/dist/convertCredentials'
import { ConnectorType } from '@prisma/generator-helper'
import chalk from 'chalk'
import dotenv from 'dotenv'
Expand Down Expand Up @@ -216,9 +213,7 @@ export class Init implements Command {
}
}

provider = databaseTypeToConnectorType(
protocolToDatabaseType(`${args['--url'].split(':')[0]}:`),
)
provider = protocolToConnectorType(`${args['--url'].split(':')[0]}:`)
url = args['--url']
} else if (args['--datasource-provider']) {
const providerLowercase = args['--datasource-provider'].toLowerCase()
Expand Down
9 changes: 2 additions & 7 deletions packages/migrate/src/commands/DbPull.ts
Expand Up @@ -17,10 +17,7 @@ import {
} from '@prisma/sdk'
import { formatms } from '../utils/formatms'
import fs from 'fs'
import {
protocolToDatabaseType,
databaseTypeToConnectorType,
} from '@prisma/sdk/dist/convertCredentials'
import { protocolToConnectorType } from '@prisma/sdk/dist/convertCredentials'
import { printDatasources } from '../utils/printDatasources'
import { removeDatasource } from '../utils/removeDatasource'
import { NoSchemaFoundError } from '../utils/errors'
Expand Down Expand Up @@ -59,9 +56,7 @@ Instead of saving the result to the filesystem, you can also print it to stdout
`)

private printUrlAsDatasource(url: string): string {
const provider = databaseTypeToConnectorType(
protocolToDatabaseType(`${url.split(':')[0]}:`),
)
const provider = protocolToConnectorType(`${url.split(':')[0]}:`)

return printDatasources([
{
Expand Down
21 changes: 2 additions & 19 deletions packages/sdk/src/convertCredentials.ts
Expand Up @@ -82,7 +82,7 @@ export function uriToCredentials(
)
}

const type = protocolToDatabaseType(uri.protocol)
const type = protocolToConnectorType(uri.protocol)

// needed, as the URL implementation adds empty strings
const exists = (str): boolean => str && str.length > 0
Expand Down Expand Up @@ -161,7 +161,7 @@ function databaseTypeToProtocol(databaseType: ConnectorType): string {
}
}

export function protocolToDatabaseType(protocol: string): ConnectorType {
export function protocolToConnectorType(protocol: string): ConnectorType {
switch (protocol) {
case 'postgresql:':
case 'postgres:':
Expand All @@ -180,20 +180,3 @@ export function protocolToDatabaseType(protocol: string): ConnectorType {

throw new Error(`Unknown database type ${protocol}`)
}

export function databaseTypeToConnectorType(
databaseType: ConnectorType,
): ConnectorType {
switch (databaseType) {
case 'postgresql':
return 'postgresql'
case 'mysql':
return 'mysql'
case 'sqlite':
return 'sqlite'
case 'sqlserver':
return 'sqlserver'
}

throw new Error(`Mongo is not yet supported`)
}
9 changes: 2 additions & 7 deletions packages/sdk/src/migrateEngineCommands.ts
Expand Up @@ -4,10 +4,7 @@ import fs from 'fs'
import path from 'path'
import { promisify } from 'util'
import { getSchemaDir } from './cli/getSchema'
import {
databaseTypeToConnectorType,
protocolToDatabaseType,
} from './convertCredentials'
import { protocolToConnectorType } from './convertCredentials'
import { resolveBinary } from './resolveBinary'

const exists = promisify(fs.exists)
Expand Down Expand Up @@ -91,9 +88,7 @@ export async function canConnectToDatabase(
)
}

const provider = databaseTypeToConnectorType(
protocolToDatabaseType(`${connectionString.split(':')[0]}:`),
)
const provider = protocolToConnectorType(`${connectionString.split(':')[0]}:`)

if (provider === 'sqlite') {
const sqliteExists = await doesSqliteDbExist(connectionString, cwd)
Expand Down

0 comments on commit a69bff8

Please sign in to comment.