MCPcopy
hub / github.com/prisma/prisma / DbExecute

Class DbExecute

packages/migrate/src/commands/DbExecute.ts:41–164  ·  packages/migrate/src/commands/DbExecute.ts::DbExecute

Source from the content-addressed store, hash-verified

39)
40
41export class DbExecute implements Command {
42 public static new(): DbExecute {
43 return new DbExecute()
44 }
45
46 class="cm">// TODO: This command needs to get proper support for `prisma.config.ts` eventually. Not just taking the schema path
47 class="cm">// from prisma.config.ts but likely to support driver adapters, too?
48 class="cm">// See https://linear.app/prisma-company/issue/ORM-639/prisma-db-execute-support-prismaconfigts-and-driver-adapters
49 private static help = format(`
50${process.platform === class="st">'win32' ? class="st">'' : class="st">'📝 '}Execute native commands to your database
51
52This command takes as input a datasource defined in ${italic(class="st">'prisma.config.ts')} and a script, using ${green(
53 `--stdin`,
54 )} or ${green(`--file`)}.
55The script input parameters are mutually exclusive, only 1 must be provided.
56
57The output of the command is connector-specific, and is not meant for returning data, but only to report success or failure.
58
59On SQL databases, this command takes as input a SQL script.
60The whole script will be sent as a single command to the database.
61
62${italic(`This command is currently not supported on MongoDB.`)}
63
64${helpOptions}
65${bold(class="st">'Examples')}
66
67 Execute the content of a SQL script file using the datasource configured in prisma.config.ts
68 ${dim(class="st">'$')} prisma db execute --file ./script.sql
69
70 Execute the SQL script from stdin using the configured datasource
71 ${dim(class="st">'$')} echo class="st">'TRUNCATE TABLE dev;' | \\
72 prisma db execute \\
73 --stdin
74`)
75
76 public async parse(argv: string[], config: PrismaConfigInternal, baseDir: string): Promise<string | Error> {
77 const args = arg(
78 argv,
79 {
80 class="st">'--help': Boolean,
81 class="st">'-h': class="st">'--help',
82 class="st">'--config': String,
83 class="st">'--stdin': Boolean,
84 class="st">'--file': String,
85 class="st">'--telemetry-information': String,
86 },
87 false,
88 )
89
90 if (isError(args)) {
91 return this.help(args.message)
92 }
93
94 if (args[class="st">'--help']) {
95 return this.help()
96 }
97
98 const cmd = class="st">'db execute'

Callers

nothing calls this directly

Calls 1

formatFunction · 0.90

Tested by

no test coverage detected