Skip to content

Commit 1618c8a

Browse files
committed
Merge branch 'release/0.9.1'
2 parents 457418c + d7beb46 commit 1618c8a

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ src/ws4sqlite
22
test/
33
bin/
44
.vscode/
5-
Snippets
5+
/notes
66

77
# Created by https://www.toptal.com/developers/gitignore/api/go,visualstudiocode,macos,linux
88
# Edit at https://www.toptal.com/developers/gitignore?templates=go,visualstudiocode,macos,linux

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# 🌱 ws4sqlite
22

3-
**ws4sqlite** is a server-side application that, applied to one or more SQLite files, gives the possibility to perform SQL queries and statements on them via REST (or better, JSON over HTTP).
3+
**ws4sqlite** is a server application that, applied to one or more SQLite files, allows to perform SQL queries and statements on them via REST (or better, JSON over HTTP).
44

55
Possible use cases are the ones where remote access to a sqlite db is useful/needed, for example a data layer for a remote application, possibly serverless or even called from a web page (*after security considerations* of course).
66

7+
We are also building some client libraries that will abstract the "raw" JSON-based communication. See
8+
[here](https://github.com/proofrock/ws4sqlite-client-jvm) for Java/JVM, [here](https://github.com/proofrock/ws4sqlite-client-go)
9+
for Go(lang); others will follow.
10+
711
As a quick example, after launching it on a file `mydatabase.db`, it's possible to make a POST call to `http://localhost:12321/mydatabase`, with the following body:
812

913
```json
@@ -41,9 +45,10 @@ Obtaining an answer of
4145

4246
# Features
4347

44-
[Docs](https://germ.gitbook.io/ws4sqlite/) and a [Tutorial](https://germ.gitbook.io/ws4sqlite/tutorial).
48+
[Docs](https://germ.gitbook.io/ws4sqlite/) and a [Tutorial](https://germ.gitbook.io/ws4sqlite/tutorial). Client library for [Java/JDK](https://github.com/proofrock/ws4sqlite-client-jvm).
4549

4650
- A [**single executable file**](https://germ.gitbook.io/ws4sqlite/documentation/installation) (it's written in Go);
51+
- HTTP/JSON access, with [**client libraries**](https://germ.gitbook.io/ws4sqlite/client-libraries) for convenience;
4752
- Can load [**several databases**](https://germ.gitbook.io/ws4sqlite/documentation/configuration-file) at once, for convenience;
4853
- [**Batching**](https://germ.gitbook.io/ws4sqlite/documentation/requests#batch-parameter-values-for-a-statement) of multiple values set for a single statement;
4954
- All queries of a call are executed in a [**transaction**](https://germ.gitbook.io/ws4sqlite/documentation/requests);

src/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module ws4sqlite
33
go 1.17
44

55
require (
6-
github.com/gofiber/fiber/v2 v2.25.0
6+
github.com/gofiber/fiber/v2 v2.26.0
77
github.com/lnquy/cron v1.1.1
88
github.com/mattn/go-sqlite3 v1.14.10
99
github.com/mitchellh/go-homedir v1.1.0

src/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY
55
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
66
github.com/gofiber/fiber/v2 v2.25.0 h1:kv8dmG/sAFDFpTueCMEn4X0JS5d72pEFTKLZ3miOREw=
77
github.com/gofiber/fiber/v2 v2.25.0/go.mod h1:7efVWcBOZi1PyMWznnbitjnARPA7nYZxmQXJVod0bo0=
8+
github.com/gofiber/fiber/v2 v2.26.0 h1:Awnfqp3fqbZzV3wZWMRJ6Xo2U8X0Ls68M7tXjx52NcM=
9+
github.com/gofiber/fiber/v2 v2.26.0/go.mod h1:7efVWcBOZi1PyMWznnbitjnARPA7nYZxmQXJVod0bo0=
810
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
911
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
1012
github.com/klauspost/compress v1.14.1 h1:hLQYb23E8/fO+1u53d02A97a8UnsddcvYzq4ERRU4ds=

src/maintenance.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const bkpTimeFormat = "060102-1504"
3838
var bkpTimeGlob = strings.Repeat("?", len(bkpTimeFormat))
3939

4040
func doMaint(id string, mntCfg maintenance, db *sql.DB) func() {
41-
mllog.Warn("Parsing for db ", id)
4241
var bkpDir, bkpFile string
4342
if mntCfg.DoBackup {
4443
var err error

src/ws4sqlite.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"gopkg.in/yaml.v2"
4343
)
4444

45-
const version = "0.9.0"
45+
const version = "0.9.1"
4646

4747
// Catches the panics and converts the argument in a struct that Fiber uses to
4848
// signal the error, setting the response code and the JSON that is actually returned
@@ -282,7 +282,7 @@ func launch(cfg config, disableKeepAlive4Tests bool) {
282282
db.Mutex.Lock() // When unauthenticated waits for 2s, and doesn't parallelize, to hinder brute force attacks
283283
time.Sleep(2 * time.Second)
284284
db.Mutex.Unlock()
285-
mllog.Warnf("credentials not valid for user '%s'", user)
285+
mllog.Errorf("credentials not valid for user '%s'", user)
286286
return false
287287
}
288288
return true
@@ -487,17 +487,20 @@ func handler(c *fiber.Ctx) error {
487487
}()
488488

489489
for i := range body.Transaction {
490-
if body.Transaction[i].Query == "" && body.Transaction[i].Statement == "" {
491-
ret.Results = reportError(errors.New("neither query nor statement specified"), fiber.StatusBadRequest, i, body.Transaction[i].NoFail, ret.Results)
490+
if (body.Transaction[i].Query == "") == (body.Transaction[i].Statement == "") { // both null or both populated
491+
ret.Results = reportError(errors.New("only one of query or statement must be provided"), fiber.StatusBadRequest, i, body.Transaction[i].NoFail, ret.Results)
492492
continue
493493
}
494494

495-
if body.Transaction[i].Query != "" && body.Transaction[i].Statement != "" {
496-
ret.Results = reportError(errors.New("cannot specify both query and statement"), fiber.StatusBadRequest, i, body.Transaction[i].NoFail, ret.Results)
497-
continue
495+
hasResultSet := body.Transaction[i].Query != ""
496+
497+
if hasResultSet && body.Transaction[i].Encoder != nil {
498+
ret.Results = reportError(errors.New("cannot specify an encoder for a query"), fiber.StatusBadRequest, i, body.Transaction[i].NoFail, ret.Results)
498499
}
499500

500-
hasResultSet := body.Transaction[i].Query != ""
501+
if !hasResultSet && body.Transaction[i].Decoder != nil {
502+
ret.Results = reportError(errors.New("cannot specify a decoder for a statement"), fiber.StatusBadRequest, i, body.Transaction[i].NoFail, ret.Results)
503+
}
501504

502505
if !hasResultSet {
503506
body.Transaction[i].Query = body.Transaction[i].Statement

0 commit comments

Comments
 (0)