mirror of
https://github.com/sqlitebrowser/go-dbhub.git
synced 2025-12-21 08:29:30 -06:00
Add Webpage() function, update dependencies and column_details example
This commit is contained in:
@@ -15,10 +15,10 @@ A Go library for accessing and using SQLite databases stored remotely on DBHub.i
|
||||
* Generate diffs between two databases, or database revisions
|
||||
* Download a complete database
|
||||
* Download the database metadata (size, branches, commit list, etc.)
|
||||
* Retrieve the web page URL of the database
|
||||
|
||||
### Still to do
|
||||
|
||||
* A function for returning the web page URL of the database
|
||||
* Tests for each function
|
||||
* Have the backend server correctly use the incoming branch, release, and tag information
|
||||
* Upload a complete database
|
||||
@@ -146,5 +146,6 @@ ORDER BY table1.id;
|
||||
* [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
|
||||
* [Download database](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/download_database/main.go) - Download the complete database file
|
||||
* [Retrieve metadata](https://github.com/sqlitebrowser/go-dbhub/blob/master/examples/metadata/main.go) - Download the database metadata (size, branches, commit list, etc)
|
||||
* [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
|
||||
|
||||
Please try it out, submits PRs to extend or fix things, and report any weirdness or bugs you encounter. :smile:
|
||||
|
||||
11
dbhub.go
11
dbhub.go
@@ -286,3 +286,14 @@ func (c Connection) Views(dbOwner, dbName string, ident Identifier) (views []str
|
||||
err = sendRequestJSON(queryUrl, data, &views)
|
||||
return
|
||||
}
|
||||
|
||||
// Webpage returns the URL of the database file in the webUI. eg. for web browsers
|
||||
func (c Connection) Webpage(dbOwner, dbName string) (webPage com.WebpageResponseContainer, err error) {
|
||||
// Prepare the API parameters
|
||||
data := c.PrepareVals(dbOwner, dbName, Identifier{})
|
||||
|
||||
// Fetch the releases
|
||||
queryUrl := c.Server + "/v1/webpage"
|
||||
err = sendRequestJSON(queryUrl, data, &webPage)
|
||||
return
|
||||
}
|
||||
@@ -25,13 +25,10 @@ func main() {
|
||||
fmt.Printf("Columns on table or view '%s':\n", table)
|
||||
for _, j := range columns {
|
||||
fmt.Printf(" * '%v':\n", j.Name)
|
||||
fmt.Printf(" Autoincrement: %v\n", j.Autoinc)
|
||||
fmt.Printf(" Cid: %v\n", j.Cid)
|
||||
fmt.Printf(" Collation Sequence: %v\n", j.CollSeq)
|
||||
fmt.Printf(" Data Type: %v\n", j.DataType)
|
||||
fmt.Printf(" Default Value: %v\n", j.DfltValue)
|
||||
fmt.Printf(" Not Null: %v\n", j.NotNull)
|
||||
fmt.Printf(" Primary Key: %v\n", j.Pk)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -25,5 +25,4 @@ func main() {
|
||||
for _, j := range views {
|
||||
fmt.Printf(" * %s\n", j)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
25
examples/webpage/main.go
Normal file
25
examples/webpage/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/sqlitebrowser/go-dbhub"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create a new DBHub.io API object
|
||||
db, err := dbhub.New("YOUR_API_KEY_HERE")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Retrieve the metadata for the remote database
|
||||
wp, err := db.Webpage("justinclift", "Join Testing.sqlite")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Display the web page for the database
|
||||
fmt.Printf("Web page: '%s'\n", wp.WebPage)
|
||||
}
|
||||
2
go.mod
2
go.mod
@@ -10,4 +10,4 @@ replace (
|
||||
github.com/Sirupsen/logrus v1.6.0 => github.com/sirupsen/logrus v1.6.0
|
||||
)
|
||||
|
||||
require github.com/sqlitebrowser/dbhub.io v0.0.11
|
||||
require github.com/sqlitebrowser/dbhub.io v0.0.12
|
||||
|
||||
4
go.sum
4
go.sum
@@ -123,8 +123,8 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG
|
||||
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
|
||||
github.com/sqlitebrowser/blackfriday v9.0.0+incompatible h1:ddH/UyzasooYgGIblVU4R8DdmBuJ7QXLvSqX/0chZv4=
|
||||
github.com/sqlitebrowser/blackfriday v9.0.0+incompatible/go.mod h1:/zga9sqpWzcewuI83AO5JZwe9+6F9GgPDdqqdNNEL/0=
|
||||
github.com/sqlitebrowser/dbhub.io v0.0.11 h1:Ddkjiftx/q5+ZFbOHIvuK6mQk1ACs/3jea7AbwDJlYA=
|
||||
github.com/sqlitebrowser/dbhub.io v0.0.11/go.mod h1:GgZi8wkjdRGkkUVgYNuZp5i+Yps3jGt/jjRuLKRi6Po=
|
||||
github.com/sqlitebrowser/dbhub.io v0.0.12 h1:G5qd4qQGCVB8/Seh0e+cBvaYkpnoGnWQuxPEr4B09ZE=
|
||||
github.com/sqlitebrowser/dbhub.io v0.0.12/go.mod h1:GgZi8wkjdRGkkUVgYNuZp5i+Yps3jGt/jjRuLKRi6Po=
|
||||
github.com/sqlitebrowser/github_flavored_markdown v0.0.0-20190120045821-b8cf8f054e47 h1:s0+Ea95n1LrsKh6rtclU/9Qb2/5ofvnfnR7gDDiFTw8=
|
||||
github.com/sqlitebrowser/github_flavored_markdown v0.0.0-20190120045821-b8cf8f054e47/go.mod h1:8vPIKi5FslxCXEgfQxrFtWfdclGy6VWAc9NA1ZTYCJg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
||||
6
vendor/github.com/sqlitebrowser/dbhub.io/common/responses.go
generated
vendored
6
vendor/github.com/sqlitebrowser/dbhub.io/common/responses.go
generated
vendored
@@ -72,3 +72,9 @@ func MetadataResponse(dbOwner, dbFolder, dbName string) (meta MetadataResponseCo
|
||||
meta.WebPage = "https://" + Conf.Web.ServerName + "/" + dbOwner + "/" + dbName
|
||||
return
|
||||
}
|
||||
|
||||
// WebpageResponseContainer holds the response to a client request for the database webUI URL. It's a temporary structure,
|
||||
// mainly so the JSON created for it is consistent between our various daemons
|
||||
type WebpageResponseContainer struct {
|
||||
WebPage string `json:"web_page"`
|
||||
}
|
||||
|
||||
2
vendor/github.com/sqlitebrowser/dbhub.io/common/types.go
generated
vendored
2
vendor/github.com/sqlitebrowser/dbhub.io/common/types.go
generated
vendored
@@ -210,8 +210,6 @@ type APIJSONColumn struct {
|
||||
NotNull bool `json:"not_null"`
|
||||
DfltValue string `json:"default_value"`
|
||||
Pk int `json:"primary_key"`
|
||||
Autoinc bool `json:"autoinc"`
|
||||
CollSeq string `json:"collation_seq"`
|
||||
}
|
||||
|
||||
// APIJSONIndexColumn holds the details of one column of a SQLite database index. It's used by our API for returning
|
||||
|
||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -63,7 +63,7 @@ github.com/sourcegraph/annotate
|
||||
github.com/sourcegraph/syntaxhighlight
|
||||
# github.com/sqlitebrowser/blackfriday v9.0.0+incompatible
|
||||
github.com/sqlitebrowser/blackfriday
|
||||
# github.com/sqlitebrowser/dbhub.io v0.0.11
|
||||
# github.com/sqlitebrowser/dbhub.io v0.0.12
|
||||
## explicit
|
||||
github.com/sqlitebrowser/dbhub.io/common
|
||||
# github.com/sqlitebrowser/github_flavored_markdown v0.0.0-20190120045821-b8cf8f054e47
|
||||
|
||||
Reference in New Issue
Block a user