|
| 1 | +import type { CliOption, FileOptions, MigrateOptions, SqlOptions, UnsafeOptions } from '../src/types' |
1 | 2 | import { CAC } from 'cac'
|
2 | 3 | import { version } from '../package.json'
|
3 | 4 | import { explain, file, introspect, ping, sql, unsafe, waitReady } from '../src/actions'
|
4 | 5 | import { generateMigration } from '../src/actions/migrate'
|
5 | 6 |
|
6 | 7 | const cli = new CAC('query-builder')
|
7 | 8 |
|
8 |
| -interface CliOption { |
9 |
| - verbose: boolean |
10 |
| -} |
11 |
| - |
12 | 9 | cli
|
13 | 10 | .command('introspect <dir>', 'Load models and print inferred schema')
|
14 | 11 | .option('--verbose', 'Enable verbose logging')
|
|
21 | 18 | .command('sql <dir> <table>', 'Build a sample query for a table')
|
22 | 19 | .option('--limit <n>', 'Limit rows', { default: 10 })
|
23 | 20 | .example('query-builder sql ./app/Models users --limit 5')
|
24 |
| - .action(async (dir: string, table: string, opts: any) => { |
| 21 | + .action(async (dir: string, table: string, opts: SqlOptions) => { |
25 | 22 | await sql(dir, table, opts)
|
26 | 23 | })
|
27 | 24 |
|
|
51 | 48 | .command('unsafe <sql>', 'Execute an unsafe SQL string (one statement with params)')
|
52 | 49 | .option('--params <json>', 'JSON array of parameters')
|
53 | 50 | .example('query-builder unsafe "SELECT * FROM users WHERE id = $1" --params "[1]"')
|
54 |
| - .action(async (sql: string, opts: any) => { |
| 51 | + .action(async (sql: string, opts: UnsafeOptions) => { |
55 | 52 | await unsafe(sql, opts)
|
56 | 53 | })
|
57 | 54 |
|
|
60 | 57 | .option('--params <json>', 'JSON array of parameters')
|
61 | 58 | .example('query-builder file ./migrations/seed.sql')
|
62 | 59 | .example('query-builder file ./reports/top.sql --params "[30]"')
|
63 |
| - .action(async (path: string, opts: any) => { |
| 60 | + .action(async (path: string, opts: FileOptions) => { |
64 | 61 | await file(path, opts)
|
65 | 62 | })
|
66 | 63 |
|
|
71 | 68 | .option('--apply', 'Execute the generated SQL against the database')
|
72 | 69 | .option('--full', 'Force full migration SQL instead of incremental diff')
|
73 | 70 | .example('query-builder migrate ./app/Models --dialect postgres')
|
74 |
| - .action(async (dir: string, opts: any) => { |
| 71 | + .action(async (dir: string, opts: MigrateOptions) => { |
75 | 72 | try {
|
76 | 73 | await generateMigration(dir, {
|
77 | 74 | dialect: opts.dialect,
|
|
0 commit comments