-
Notifications
You must be signed in to change notification settings - Fork 0
/
red
executable file
·89 lines (79 loc) · 1.89 KB
/
red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!env perl6
use Red::Cli;
use Red::Do;
use Red::Database;
my %*SUB-MAIN-OPTS =
:named-anywhere,
;
my $*RED-DEBUG = False;
proto MAIN(Str :$I, Bool :$debug, |) {
dyn-lib .split: "," with $I;
$*RED-DEBUG = $debug;
{*}
}
#| List tables in database
multi MAIN(
"list-tables",
Str :$driver!,
*%pars
) {
my $*RED-DB = database($driver, |%pars);
.say for list-tables :$driver, |%pars
}
#| Generate stub code to access models from database schema
multi MAIN(
"print-stub",
Str :$schema-class,
Str :$driver!,
*%pars
) {
my $*RED-DB = database($driver, |%pars);
say gen-stub-code :$schema-class, :$driver, |%pars
}
#| Generates migration plan to upgrade database schema
multi MAIN(
"migration-plan",
Str :$model!,
Str :$require = $model,
Str :$driver!,
*%pars
) {
my $*RED-DB = database($driver, |%pars);
migration-plan :$model, :$require, :$driver, |%pars
}
#| Generates models' code from database schema
multi MAIN(
"generate-code",
Str :$path! where { not .defined or .IO.d or $_ eq "-" or fail "Path $_ does not exist." },
Str :$from-sql where { not .defined or .IO.f or $_ eq "-" or fail "SQL $_ do not exist." },
Str :$schema-class,
Bool :$print-stub = False,
Bool :$no-relationships = False,
#Bool :$stub-only,
Str :$driver!,
*%pars
) {
my $*RED-DB = database($driver, |%pars);
generate-code
:$path,
:$from-sql,
:$schema-class,
:$print-stub,
:$no-relationships,
:$driver,
|%pars
}
#| Prepare database
multi MAIN(
"prepare-database",
Bool :$populate,
Str :$models!,
Str :$driver!,
*%pars
) {
$GLOBAL::RED-DB = database $driver, |%pars;
prepare-database :$populate, :$models, :$driver, |%pars
}
sub dyn-lib(@libs) {
qq[use lib "{ $_ }"].EVAL for @libs
}