Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ozym committed Jan 17, 2025
1 parent cb0cff1 commit a2fc3be
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 620 deletions.
50 changes: 1 addition & 49 deletions cmd/deltadb/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
## deltadb

This application can build a standalone sqlite database which can be used as desired in third party applications.
It also adds an example of a limited REST API server as a technology demonstation.

This has been made possible by using the pure go module `modernc.org/sqlite`, which uses some interesting automatic
conversion of the core c-code to go to build a version that doesn't require the cgo library wrapper.

### options

```
Build a DELTA Sqlite DB and optional REST API service
Build a DELTA Sqlite DB
Usage:
Expand All @@ -23,12 +22,8 @@ Options:
name of the database file on disk
-debug
add extra operational info
-hostport string
base directory of delta files on disk (default ":8080")
-init
initialise the database if a file on disk
-listen
should a web service be enabled
-resp string
base directory of resp files on disk
-response string
Expand Down Expand Up @@ -63,49 +58,6 @@ CREATE TABLE network (
sqlite>
```

Another example which uses the built in REST API, e.g.

```
./deltadb -debug -listen
2024/11/03 20:55:11 initialise database
2024/11/03 20:55:12 database initialised in 1.181009504s
2024/11/03 20:55:12 handling requests on :8080
```

and then the service can be accessed via curl, e.g.

```
curl -s localhost:8080/network|jq .|head
[
{
"network": "AK",
"external": "NZ",
"description": "Auckland volcano seismic network"
},
{
"network": "BC",
"external": "BC",
"description": "Building monitoring camera network"
...
```

or

```
curl -s localhost:8080/station/WEL|jq . | head
[
{
"station": "WEL",
"network": "NZ",
"name": "Wellington",
"latitude": -41.284047578,
"longitude": 174.768184021,
"elevation": 138,
"datum": "WGS84",
"start": "1916-01-01T00:00:00Z",
...
```

## schema

[![Schema](delta.svg)](delta.svg)
49 changes: 0 additions & 49 deletions cmd/deltadb/handler.go

This file was deleted.

25 changes: 2 additions & 23 deletions cmd/deltadb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"log"
"net/http"
"net/url"
"os"
"time"
Expand All @@ -27,9 +26,7 @@ type Settings struct {
db string // name of the database file
response string // name of the database response table

init bool // should the database be updated
listen bool // should a web service be enabled
hostport string // hostport to listen on for the web service
init bool // should the database be updated
}

func main() {
Expand All @@ -38,7 +35,7 @@ func main() {

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Build a DELTA Sqlite DB and optional REST API service\n")
fmt.Fprintf(os.Stderr, "Build a DELTA Sqlite DB file\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Usage:\n")
fmt.Fprintf(os.Stderr, "\n")
Expand All @@ -52,13 +49,10 @@ func main() {

flag.BoolVar(&settings.debug, "debug", false, "add extra operational info")
flag.BoolVar(&settings.init, "init", false, "initialise the database if a file on disk")
flag.BoolVar(&settings.listen, "listen", false, "should a web service be enabled")

flag.StringVar(&settings.base, "base", "", "base directory of delta files on disk")
flag.StringVar(&settings.resp, "resp", "", "base directory of resp files on disk")
flag.StringVar(&settings.db, "db", "", "name of the database file on disk")
flag.StringVar(&settings.response, "response", "Response", "optional database response table name to use")
flag.StringVar(&settings.hostport, "hostport", ":8080", "base directory of delta files on disk")

flag.Parse()

Expand Down Expand Up @@ -115,19 +109,4 @@ func main() {
}
log.Printf("database initialised in %s", time.Since(start).String())
}

if !settings.listen {
return
}

log.Printf("handling requests on %s", settings.hostport)
server := &http.Server{
Addr: settings.hostport,
Handler: newHandler(db),
ReadHeaderTimeout: 3 * time.Second,
}

if err := server.ListenAndServe(); err != nil {
panic(err)
}
}
64 changes: 0 additions & 64 deletions cmd/deltadb/mark.go

This file was deleted.

65 changes: 0 additions & 65 deletions cmd/deltadb/monument.go

This file was deleted.

57 changes: 0 additions & 57 deletions cmd/deltadb/network.go

This file was deleted.

Loading

0 comments on commit a2fc3be

Please sign in to comment.