@@ -3,6 +3,7 @@ package query
3
3
import (
4
4
"fmt"
5
5
"os"
6
+ "time"
6
7
7
8
"github.com/cgi-fr/lino/internal/app/urlbuilder"
8
9
infra "github.com/cgi-fr/lino/internal/infra/query"
@@ -27,27 +28,31 @@ func Inject(
27
28
28
29
// NewCommand implements the cli analyse command
29
30
func NewCommand (fullName string , err * os.File , out * os.File , in * os.File ) * cobra.Command {
31
+ var maxLifeTime time.Duration
32
+
30
33
cmd := & cobra.Command {
31
34
Use : "query" ,
32
35
Short : "Execute direct query" ,
33
36
Example : fmt .Sprintf (" %[1]s" , fullName ),
34
37
Args : cobra .ExactArgs (2 ),
35
38
Run : func (cmd * cobra.Command , args []string ) {
36
- if er := execute (cmd , args [0 ], args [1 ]); er != nil {
39
+ if er := execute (cmd , args [0 ], args [1 ], maxLifeTime ); er != nil {
37
40
fmt .Fprintln (err , er .Error ())
38
41
os .Exit (1 )
39
42
}
40
43
},
41
44
}
42
45
46
+ cmd .Flags ().DurationVarP (& maxLifeTime , "timeout" , "t" , 4 * time .Minute , "sets the maximum amount of time a connection may be reused" )
47
+
43
48
cmd .SetOut (out )
44
49
cmd .SetErr (err )
45
50
cmd .SetIn (in )
46
51
47
52
return cmd
48
53
}
49
54
50
- func execute (cmd * cobra.Command , dataconnectorName string , querystr string ) error {
55
+ func execute (cmd * cobra.Command , dataconnectorName string , querystr string , maxLifeTime time. Duration ) error {
51
56
alias , e1 := dataconnector .Get (dataconnectorStorage , dataconnectorName )
52
57
if e1 != nil {
53
58
return e1
@@ -64,7 +69,7 @@ func execute(cmd *cobra.Command, dataconnectorName string, querystr string) erro
64
69
return fmt .Errorf ("no extractor found for database type" )
65
70
}
66
71
67
- driver := query .NewDriver (dataSourceFactory .New (u .URL .String ()), infra .NewJSONWriter (cmd .OutOrStdout ()))
72
+ driver := query .NewDriver (dataSourceFactory .New (u .URL .String (), maxLifeTime ), infra .NewJSONWriter (cmd .OutOrStdout ()))
68
73
69
74
if err := driver .Open (); err != nil {
70
75
return fmt .Errorf ("%w" , err )
0 commit comments