(props?: {
datasourceProvider?: ConnectorType
generatorProvider?: string
previewFeatures?: string[]
output?: string
withModel?: boolean
})
| 43 | !!globalThis.Bun || !!globalThis.process?.versions?.bun |
| 44 | |
| 45 | export const defaultSchema = (props?: { |
| 46 | datasourceProvider?: ConnectorType |
| 47 | generatorProvider?: string |
| 48 | previewFeatures?: string[] |
| 49 | output?: string |
| 50 | withModel?: boolean |
| 51 | }) => { |
| 52 | const { |
| 53 | datasourceProvider = 'postgresql', |
| 54 | generatorProvider = defaultGeneratorProvider, |
| 55 | previewFeatures = defaultPreviewFeatures, |
| 56 | output = '../generated/prisma', |
| 57 | withModel = false, |
| 58 | } = props ?? {} |
| 59 | |
| 60 | let schema = `// This is your Prisma schema file, |
| 61 | // learn more about it in the docs: https://pris.ly/d/prisma-schema |
| 62 | |
| 63 | // Get a free hosted Postgres database in seconds: \`npx create-db\` |
| 64 | |
| 65 | generator client { |
| 66 | provider = "${generatorProvider}" |
| 67 | ${ |
| 68 | previewFeatures.length > 0 |
| 69 | ? ` previewFeatures = [${previewFeatures.map((feature) => `"${feature}"`).join(', ')}]\n` |
| 70 | : '' |
| 71 | } output = "${output}" |
| 72 | } |
| 73 | |
| 74 | datasource db { |
| 75 | provider = "${datasourceProvider}" |
| 76 | } |
| 77 | ` |
| 78 | |
| 79 | // We add a model to the schema file if the user passed the --with-model flag |
| 80 | if (withModel) { |
| 81 | const defaultAttributes = `email String @unique |
| 82 | name String?` |
| 83 | |
| 84 | switch (datasourceProvider) { |
| 85 | case 'mongodb': |
| 86 | schema += ` |
| 87 | model User { |
| 88 | id String @id @default(auto()) @map("_id") @db.ObjectId |
| 89 | ${defaultAttributes} |
| 90 | } |
| 91 | ` |
| 92 | break |
| 93 | case 'cockroachdb': |
| 94 | schema += ` |
| 95 | model User { |
| 96 | id BigInt @id @default(sequence()) |
| 97 | ${defaultAttributes} |
| 98 | } |
| 99 | ` |
| 100 | break |
| 101 | default: |
| 102 | schema += ` |
no outgoing calls
no test coverage detected