Skip to content

Commit 96d73f1

Browse files
committed
Add badges for GoDoc and Go Report Card, add SQL query example
1 parent d9f8e77 commit 96d73f1

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
A Go library for accessing and using SQLite databases on DBHub.io
1+
[![GoDoc](https://godoc.org/github.com/sqlitebrowser/go-dbhub?status.svg)](https://godoc.org/github.com/sqlitebrowser/go-dbhub)
2+
[![Go Report Card](https://goreportcard.com/badge/github.com/sqlitebrowser/go-dbhub)](https://goreportcard.com/report/github.com/sqlitebrowser/go-dbhub)
3+
4+
A Go library for accessing and using SQLite databases stored remotely on DBHub.io
25

36
*This is an early stage work in progress*
47

58
What works now:
69

7-
* Running any read-only query (eg SELECT statements) on databases, returning the results
8-
* Listing the tables, views, indexes, and columns present in a database
10+
* Run read-only queries (eg SELECT statements) on databases, returning the results as JSON
11+
* List the names of tables, views, and indexes present in a database
12+
* List the columns present in a table or view, along with their details
13+
14+
Still to do:
15+
16+
* Tests for each function
17+
* Retrieve index details for a database
18+
* Return the list of available databases
19+
* Download a complete database
20+
* Upload a complete database
21+
* Retrieve database commit history details (size, branch, commit list, whatever else is useful)
922

1023
Example code:
1124

@@ -27,6 +40,18 @@ fmt.Println("Tables:")
2740
for _, j := range tables {
2841
fmt.Printf(" * %s\n", j)
2942
}
43+
44+
// Run a SQL query on the remote database
45+
r, err := db.Query("justinclift", "Join Testing.sqlite", false,
46+
`SELECT table1.Name, table2.value
47+
FROM table1 JOIN table2
48+
USING (id)
49+
ORDER BY table1.id`)
50+
if err != nil {
51+
log.Fatal(err)
52+
}
53+
fmt.Printf("Query results:\n\t%v\n", r)
54+
fmt.Println()
3055
```
3156

3257
Output:
@@ -35,6 +60,9 @@ Output:
3560
Tables:
3661
* table1
3762
* table2
63+
64+
Query results:
65+
{[{[Foo 5]} {[Bar 10]} {[Baz 15]} {[Blumph 12.5000]} {[Blargo 8]} {[Batty 3]}]}
3866
```
3967

40-
Please try it out, and report any weirdness or bugs you encounter. :smile:
68+
Please try it out, submits PRs, and report any weirdness or bugs you encounter. :smile:

dbhub.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
package dbhub
22

3-
// An library for working with databases on DBHub.io
4-
5-
// TODO:
6-
// * Add tests for each function
7-
// * Create function(s) for listing indexes in the remote database
8-
// * Create function to list columns in a table or view
9-
// * Create function for returning a list of available databases
10-
// * Create function for downloading complete database
11-
// * Create function for uploading complete database
12-
// * Create function for retrieving database details (size, branch, commit list, whatever else is useful)
13-
// * Make a reasonable example application written in Go
3+
// A Go library for working with databases on DBHub.io
144

155
import (
166
"encoding/base64"
@@ -21,7 +11,7 @@ import (
2111
)
2212

2313
const (
24-
LibraryVersion = "0.0.1"
14+
version = "0.0.1"
2515
)
2616

2717
// New creates a new DBHub.io connection object. It doesn't connect to DBHub.io to do this. Connection only occurs

http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func sendRequest(queryUrl string, data url.Values, returnStructure interface{})
1919
return
2020
}
2121
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
22-
req.Header.Set("User-Agent", fmt.Sprintf("go-dbhub v%s", LibraryVersion))
22+
req.Header.Set("User-Agent", fmt.Sprintf("go-dbhub v%s", version))
2323
resp, err = client.Do(req)
2424
if err != nil {
2525
return

types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package dbhub
22

3+
// Connection is a simple container holding the API key and address of the DBHub.io server
34
type Connection struct {
45
APIKey string `json:"api_key"`
56
Server string `json:"server"`
67
}
78

9+
// ResultRow is used for returning the results of a SQL query as a slice of strings
810
type ResultRow struct {
911
Fields []string
1012
}
1113

14+
// Results is used for returning the results of a SQL query as a slice of strings
1215
type Results struct {
1316
Rows []ResultRow
1417
}

0 commit comments

Comments
 (0)