Skip to content

Commit 4a4f54b

Browse files
committed
Add Delete() function, update vendored dependencies
1 parent fb476f8 commit 4a4f54b

File tree

8 files changed

+60
-9
lines changed

8 files changed

+60
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ A Go library for accessing and using SQLite databases stored remotely on DBHub.i
2222
* Have the backend server correctly use the incoming branch, release, and tag information
2323
* Tests for each function
2424
* Investigate what would be needed for this to work through the Go SQL API
25+
* Probably need to improve the Query approach, to at least support placeholders and argument parameters
2526
* Anything else people suggest and seems like a good idea :smile:
2627

2728
### Requirements
@@ -143,7 +144,9 @@ ORDER BY table1.id;
143144
* [List tags](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/list_tags/main.go) - Display the tags for a database
144145
* [List commits](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/list_commits/main.go) - Display the commits for a database
145146
* [Generate diff between two revisions](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/diff_commits/main.go) - Figure out the differences between two databases or two versions of one database
147+
* [Upload database](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/upload/main.go) - Upload a new database file
146148
* [Download database](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/download_database/main.go) - Download the complete database file
149+
* [Delete database](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/delete_database/main.go) - Delete a database
147150
* [Retrieve metadata](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/metadata/main.go) - Download the database metadata (size, branches, commit list, etc)
148151
* [Web page](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/webpage/main.go) - Get the URL of the database file in the webUI. eg. for web browsers
149152

dbhub.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ func (c Connection) Databases() (databases []string, err error) {
8888
return
8989
}
9090

91+
// Delete deletes a database in your account
92+
func (c Connection) Delete(dbName string) (err error) {
93+
// Prepare the API parameters
94+
data := c.PrepareVals("", dbName, Identifier{})
95+
96+
// Delete the database
97+
queryUrl := c.Server + "/v1/delete"
98+
err = sendRequestJSON(queryUrl, data, nil)
99+
return
100+
}
101+
91102
// Diff returns the differences between two commits of two databases, or if the details on the second database are left empty,
92103
// between two commits of the same database. You can also specify the merge strategy used for the generated SQL statements.
93104
func (c Connection) Diff(dbOwnerA, dbNameA string, identA Identifier, dbOwnerB, dbNameB string, identB Identifier, merge MergeStrategy) (diffs com.Diffs, err error) {
@@ -181,8 +192,12 @@ func (c Connection) PrepareVals(dbOwner, dbName string, ident Identifier) (data
181192
// Prepare the API parameters
182193
data = url.Values{}
183194
data.Set("apikey", c.APIKey)
184-
data.Set("dbowner", dbOwner)
185-
data.Set("dbname", dbName)
195+
if dbOwner != "" {
196+
data.Set("dbowner", dbOwner)
197+
}
198+
if dbName != "" {
199+
data.Set("dbname", dbName)
200+
}
186201
if ident.Branch != "" {
187202
data.Set("branch", ident.Branch)
188203
}

examples/delete_database/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/sqlitebrowser/go-dbhub"
8+
)
9+
10+
func main() {
11+
// Create a new DBHub.io API object
12+
db, err := dbhub.New("YOUR_API_KEY_HERE")
13+
if err != nil {
14+
log.Fatal(err)
15+
}
16+
17+
// Delete a remote database
18+
dbName := "Join Testing.sqlite"
19+
err = db.Delete(dbName)
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
24+
// Display a success message
25+
fmt.Printf("Database '%s' deleted\n", dbName)
26+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ replace (
1010
github.com/Sirupsen/logrus v1.6.0 => github.com/sirupsen/logrus v1.6.0
1111
)
1212

13-
require github.com/sqlitebrowser/dbhub.io v0.0.13
13+
require github.com/sqlitebrowser/dbhub.io v0.0.14

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG
123123
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
124124
github.com/sqlitebrowser/blackfriday v9.0.0+incompatible h1:ddH/UyzasooYgGIblVU4R8DdmBuJ7QXLvSqX/0chZv4=
125125
github.com/sqlitebrowser/blackfriday v9.0.0+incompatible/go.mod h1:/zga9sqpWzcewuI83AO5JZwe9+6F9GgPDdqqdNNEL/0=
126-
github.com/sqlitebrowser/dbhub.io v0.0.13 h1:R29VyPD6LZmtsDicbK4ICnW4RnhiqN3c8+vvKS8RzHM=
127-
github.com/sqlitebrowser/dbhub.io v0.0.13/go.mod h1:GgZi8wkjdRGkkUVgYNuZp5i+Yps3jGt/jjRuLKRi6Po=
126+
github.com/sqlitebrowser/dbhub.io v0.0.14 h1:M//NHuEpEiTj5itk95UL/CzhskkIG32BnT9Aob9l/2M=
127+
github.com/sqlitebrowser/dbhub.io v0.0.14/go.mod h1:GgZi8wkjdRGkkUVgYNuZp5i+Yps3jGt/jjRuLKRi6Po=
128128
github.com/sqlitebrowser/github_flavored_markdown v0.0.0-20190120045821-b8cf8f054e47 h1:s0+Ea95n1LrsKh6rtclU/9Qb2/5ofvnfnR7gDDiFTw8=
129129
github.com/sqlitebrowser/github_flavored_markdown v0.0.0-20190120045821-b8cf8f054e47/go.mod h1:8vPIKi5FslxCXEgfQxrFtWfdclGy6VWAc9NA1ZTYCJg=
130130
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

http.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ func sendRequestJSON(queryUrl string, data url.Values, returnStructure interface
3333
}
3434

3535
// Unmarshall the JSON response into the structure provided by the caller
36-
err = json.NewDecoder(body).Decode(returnStructure)
37-
if err != nil {
38-
return
36+
if returnStructure != nil {
37+
err = json.NewDecoder(body).Decode(returnStructure)
38+
if err != nil {
39+
return
40+
}
3941
}
4042
return
4143
}

vendor/github.com/sqlitebrowser/dbhub.io/common/responses.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ github.com/sourcegraph/annotate
6363
github.com/sourcegraph/syntaxhighlight
6464
# github.com/sqlitebrowser/blackfriday v9.0.0+incompatible
6565
github.com/sqlitebrowser/blackfriday
66-
# github.com/sqlitebrowser/dbhub.io v0.0.13
66+
# github.com/sqlitebrowser/dbhub.io v0.0.14
6767
## explicit
6868
github.com/sqlitebrowser/dbhub.io/common
6969
# github.com/sqlitebrowser/github_flavored_markdown v0.0.0-20190120045821-b8cf8f054e47

0 commit comments

Comments
 (0)