Skip to content

Commit 3afbf5b

Browse files
committed
Add --query-timeout and --connection-timeout options
1 parent 3ea85fd commit 3afbf5b

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

cmd/schemagen/schemagen.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,25 @@ import (
2121
_ "github.com/scylladb/gocqlx/v3/table"
2222
)
2323

24+
var defaultClusterConfig = gocql.NewCluster()
25+
26+
var (
27+
defaultQueryTimeout = defaultClusterConfig.Timeout
28+
defaultConnectionTimeout = defaultClusterConfig.ConnectTimeout
29+
)
30+
2431
var (
25-
cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
26-
flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
27-
flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect")
28-
flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package")
29-
flagOutput = cmd.String("output", "models", "the name of the folder to output to")
30-
flagUser = cmd.String("user", "", "user for password authentication")
31-
flagPassword = cmd.String("password", "", "password for password authentication")
32-
flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore")
33-
flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes")
32+
cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
33+
flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
34+
flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect")
35+
flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package")
36+
flagOutput = cmd.String("output", "models", "the name of the folder to output to")
37+
flagUser = cmd.String("user", "", "user for password authentication")
38+
flagPassword = cmd.String("password", "", "password for password authentication")
39+
flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore")
40+
flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes")
41+
flagQueryTimeout = cmd.Duration("query-timeout", defaultQueryTimeout, "query timeout ( in seconds )")
42+
flagConnectionTimeout = cmd.Duration("connection-timeout", defaultConnectionTimeout, "connection timeout ( in seconds )")
3443
)
3544

3645
//go:embed keyspace.tmpl
@@ -152,6 +161,12 @@ func createSession() (gocqlx.Session, error) {
152161
Password: *flagPassword,
153162
}
154163
}
164+
if *flagQueryTimeout >= 0 {
165+
cluster.Timeout = *flagQueryTimeout
166+
}
167+
if *flagConnectionTimeout >= 0 {
168+
cluster.ConnectTimeout = *flagConnectionTimeout
169+
}
155170
return gocqlx.WrapSession(cluster.CreateSession())
156171
}
157172

0 commit comments

Comments
 (0)