Skip to content

Commit e87c739

Browse files
Merge pull request #6 from sqlitecloud/#5-parameters-connection-string
#5 - implement available parameters
2 parents 982e6f2 + b29323c commit e87c739

18 files changed

+671
-117
lines changed

.devcontainer/devcontainer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/go
3+
{
4+
"name": "Go",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/go:1-1-bullseye"
7+
8+
// Features to add to the dev container. More info: https://containers.dev/features.
9+
// "features": {},
10+
11+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
12+
// "forwardPorts": [],
13+
14+
// Use 'postCreateCommand' to run commands after the container is created.
15+
// "postCreateCommand": "go version",
16+
17+
// Configure tool-specific properties.
18+
// "customizations": {},
19+
20+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
21+
// "remoteUser": "root"
22+
}

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SQLITE_CONNECTION_STRING=sqlitecloud://myhost.sqlite.cloud
2+
SQLITE_USER=admin
3+
SQLITE_PASSWORD=
4+
SQLITE_API_KEY=
5+
SQLITE_HOST=myhost.sqlite.cloud
6+
SQLITE_DB=chinook.sqlite
7+
SQLITE_PORT=8860

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ cli/.DS_Store
33
.DS_Store
44
cli/.vscode
55
.vscode/launch.json
6+
pkg/
7+
bin
8+
.env

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"gopls": {
3+
"ui.semanticTokens": true
4+
}
5+
}

cli/sqlc.go

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ Connection Options:
9191
-w, --password PASSWORD Use PASSWORD for authentication
9292
-t, --timeout SECS Set Timeout for network operations to SECS seconds [default::10]
9393
-c, --compress (NO|LZ4) Use line compression [default::NO]
94+
-z, --zerotext Text ends with 0 value
95+
-m, --memory Use in-memory database
96+
-e, --create Create database if it does not exist
97+
-i, --nonlinearizable Use non-linearizable mode for queries
98+
-a, --apikey KEY Use API key for authentication
99+
-n, --noblob Disable BLOB support
100+
-x, --maxdata SIZE Set maximum data size for queries
101+
-y, --maxrows ROWS Set maximum number of rows for queries
102+
-r, --maxrowset ROWS Set maximum number of rows per rowset for queries
94103
--tls [YES|NO|INTERN|FILE] Encrypt the database connection using the host's root CA set (YES), a custom CA with a PEM from FILE (FILE), the internal SQLiteCloud CA (INTERN), or disable the encryption (NO) [default::YES]
95104
`
96105

@@ -131,16 +140,20 @@ type Parameter struct {
131140
Format string `docopt:"--format"`
132141
OutPutFormat int `docopt:"--outputformat"`
133142

134-
Host string `docopt:"--host"`
135-
Port int `docopt:"--port"`
136-
User string `docopt:"--user"`
137-
Password string `docopt:"--password"`
138-
Database string `docopt:"--dbname"`
139-
ApiKey string `docopt:"--apikey"`
140-
NoBlob bool `docopt:"--noblob"`
141-
MaxData int `docopt:"--maxdata"`
142-
MaxRows int `docopt:"--maxrows"`
143-
MaxRowset int `docopt:"--maxrowset"`
143+
Host string `docopt:"--host"`
144+
Port int `docopt:"--port"`
145+
User string `docopt:"--user"`
146+
Password string `docopt:"--password"`
147+
Database string `docopt:"--dbname"`
148+
Zerotext bool `docopt:"--zerotext"`
149+
Memory bool `docopt:"--memory"`
150+
Create bool `docopt:"--create"`
151+
NonLinearizable bool `docopt:"--nonlinearizable"`
152+
ApiKey string `docopt:"--apikey"`
153+
NoBlob bool `docopt:"--noblob"`
154+
MaxData int `docopt:"--maxdata"`
155+
MaxRows int `docopt:"--maxrows"`
156+
MaxRowset int `docopt:"--maxrowset"`
144157

145158
Timeout int `docopt:"--timeout"`
146159
Compress string `docopt:"--compress"`
@@ -245,23 +258,46 @@ func parseParameters() (Parameter, error) {
245258
p["--user"] = getFirstNoneEmptyString([]string{dropError(p.String("--user")), conf.Username})
246259
p["--password"] = getFirstNoneEmptyString([]string{dropError(p.String("--password")), conf.Password})
247260
p["--dbname"] = getFirstNoneEmptyString([]string{dropError(p.String("--dbname")), conf.Database})
248-
p["--host"] = getFirstNoneEmptyString([]string{dropError(p.String("--host")), conf.Host})
249-
p["--compress"] = getFirstNoneEmptyString([]string{dropError(p.String("--compress")), conf.CompressMode})
250261
if conf.Port > 0 {
251262
p["--port"] = getFirstNoneEmptyString([]string{dropError(p.String("--port")), fmt.Sprintf("%d", conf.Port)})
252263
}
253264
if conf.Timeout > 0 {
254265
p["--timeout"] = getFirstNoneEmptyString([]string{dropError(p.String("--timeout")), fmt.Sprintf("%d", conf.Timeout)})
255266
}
267+
if conf.Compression {
268+
p["--compress"] = getFirstNoneEmptyString([]string{dropError(p.String("--compress")), conf.CompressMode})
269+
}
270+
if conf.Zerotext {
271+
if b, err := p.Bool("--zerotext"); err == nil {
272+
p["--zerotext"] = b || conf.Zerotext
273+
}
274+
}
275+
if conf.Memory {
276+
if b, err := p.Bool("--memory"); err == nil {
277+
p["--memory"] = b || conf.Memory
278+
}
279+
}
280+
if conf.Create {
281+
if b, err := p.Bool("--create"); err == nil {
282+
p["--create"] = b || conf.Create
283+
}
284+
}
285+
if conf.NonLinearizable {
286+
if b, err := p.Bool("--nonlinearizable"); err == nil {
287+
p["--nonlinearizable"] = b || conf.NonLinearizable
288+
}
289+
}
256290
p["--tls"] = getFirstNoneEmptyString([]string{dropError(p.String("--tls")), conf.Pem})
257-
if conf.Secure == false {
291+
if !conf.Secure {
258292
p["--tls"] = "NO"
259-
} else if conf.TlsInsecureSkipVerify == true {
293+
} else if conf.TlsInsecureSkipVerify {
260294
p["--tls"] = "SKIP"
261295
}
262296
p["--apikey"] = getFirstNoneEmptyString([]string{dropError(p.String("--apikey")), conf.ApiKey})
263297
if conf.NoBlob {
264-
p["--noblob"] = getFirstNoneEmptyString([]string{dropError(p.String("--noblob")), strconv.FormatBool(conf.NoBlob)})
298+
if b, err := p.Bool("--noblob"); err == nil {
299+
p["--noblob"] = b || conf.NoBlob
300+
}
265301
}
266302
if conf.MaxData > 0 {
267303
p["--maxdata"] = getFirstNoneEmptyString([]string{dropError(p.String("--maxdata")), fmt.Sprintf("%d", conf.MaxData)})
@@ -284,6 +320,9 @@ func parseParameters() (Parameter, error) {
284320
p["--compress"] = getFirstNoneEmptyString([]string{dropError(p.String("--compress")), "NO"})
285321
p["--tls"] = getFirstNoneEmptyString([]string{dropError(p.String("--tls")), "YES"})
286322
p["--separator"] = getFirstNoneEmptyString([]string{dropError(p.String("--separator")), dropError(sqlitecloud.GetDefaultSeparatorForOutputFormat(outputformat)), "|"})
323+
p["--maxdata"] = getFirstNoneEmptyString([]string{dropError(p.String("--maxdata")), "0"})
324+
p["--maxrows"] = getFirstNoneEmptyString([]string{dropError(p.String("--maxrows")), "0"})
325+
p["--maxrowset"] = getFirstNoneEmptyString([]string{dropError(p.String("--maxrowset")), "0"})
287326

288327
// Fix invalid(=unset) parameters, quotation & control-chars
289328
for k, v := range p {
@@ -375,18 +414,22 @@ func main() {
375414
// print( out, fmt.Sprintf( "%s %s, %s", long_name, version, copyright ), &parameter )
376415

377416
config := sqlitecloud.SQCloudConfig{
378-
Host: parameter.Host,
379-
Port: parameter.Port,
380-
Username: parameter.User,
381-
Password: parameter.Password,
382-
Database: parameter.Database,
383-
Timeout: time.Duration(parameter.Timeout) * time.Second,
384-
CompressMode: parameter.Compress,
385-
ApiKey: parameter.ApiKey,
386-
NoBlob: parameter.NoBlob,
387-
MaxData: parameter.MaxData,
388-
MaxRows: parameter.MaxRows,
389-
MaxRowset: parameter.MaxRowset,
417+
Host: parameter.Host,
418+
Port: parameter.Port,
419+
Username: parameter.User,
420+
Password: parameter.Password,
421+
Database: parameter.Database,
422+
Timeout: time.Duration(parameter.Timeout) * time.Second,
423+
CompressMode: parameter.Compress,
424+
Zerotext: parameter.Zerotext,
425+
Memory: parameter.Memory,
426+
Create: parameter.Create,
427+
NonLinearizable: parameter.NonLinearizable,
428+
ApiKey: parameter.ApiKey,
429+
NoBlob: parameter.NoBlob,
430+
MaxData: parameter.MaxData,
431+
MaxRows: parameter.MaxRows,
432+
MaxRowset: parameter.MaxRowset,
390433
}
391434

392435
config.Secure, config.TlsInsecureSkipVerify, config.Pem = sqlitecloud.ParseTlsString(parameter.Tls)
@@ -514,7 +557,7 @@ func main() {
514557
case ".timeout":
515558
parameter.Timeout = getNextTokenValueAsInteger(out, parameter.Timeout, 10, tokens, &parameter)
516559
case ".compress":
517-
parameter.Compress = getNextTokenValueAsString(out, parameter.Compress, "NO", "|no|lz4|", tokens, &parameter)
560+
parameter.Compress = getNextTokenValueAsString(out, parameter.Compress, sqlitecloud.CompressModeNo, "|no|lz4|", tokens, &parameter)
518561
db.Compress(parameter.Compress)
519562

520563
case ".format":

0 commit comments

Comments
 (0)