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

Class DbExecute

packages/migrate/src/commands/DbExecute.ts:41–164  ·  view source on GitHub ↗

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 // TODO: This command needs to get proper support for `prisma.config.ts` eventually. Not just taking the schema path
47 // from prisma.config.ts but likely to support driver adapters, too?
48 // 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 === 'win32' ? '' : '📝 '}Execute native commands to your database
51
52This command takes as input a datasource defined in ${italic('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('Examples')}
66
67 Execute the content of a SQL script file using the datasource configured in prisma.config.ts
68 ${dim('$')} prisma db execute --file ./script.sql
69
70 Execute the SQL script from stdin using the configured datasource
71 ${dim('$')} echo '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 '--help': Boolean,
81 '-h': '--help',
82 '--config': String,
83 '--stdin': Boolean,
84 '--file': String,
85 '--telemetry-information': String,
86 },
87 false,
88 )
89
90 if (isError(args)) {
91 return this.help(args.message)
92 }
93
94 if (args['--help']) {
95 return this.help()
96 }
97
98 const cmd = 'db execute'

Callers

nothing calls this directly

Calls 1

formatFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…