Skip to content

Commit 6ae7116

Browse files
committed
chore: code cleaning, preparing for v1.0.0
1 parent eeb614a commit 6ae7116

7 files changed

Lines changed: 105 additions & 20 deletions

File tree

MAKEFILE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SQLite Cloud go-sdk Makefile
2+
3+
### Run the test for the SDK
4+
If you want to run the Test programs: `make test`
5+
6+
### Building the CLI App
7+
To build the CLI App, you have to enter: `make cli`
8+
9+
### Build all at the same time:
10+
If you want to do all at the same time: `make all`
11+
12+
## Documentation
13+
If you want to see the Documentation: `make doc` - Warning: A browser window will open and display the documentation to you. The Documentation is updated live while coding. To stop the live mode, press CRTL-C on the command line.
14+
15+
## Development helpers
16+
- Check files with gosec: `make checksec`
17+
- Open the repo in github: `make github`.
18+
- See changes: `make diff`
19+
- Clean dependencies and precompiled code: `make clean`

README.md

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,88 @@
1-
# SQLite Cloud GO Client
21

3-
### Run the test for the SDK
4-
If you want to run the Test programs: `make test`
2+
# Introduction
53

6-
### Building the CLI App
7-
To build the CLI App, you have to enter: `make cli`
4+
The SQLite Cloud Client SDK for Go (sqlitecloud/go-sdk) is the Go Programming Language application programmer's interface to [SQLite Cloud](https://sqlitecloud.io/).
85

9-
### Build all at the same time:
10-
If you want to do all at the same time: `make all`
6+
It is a set of library functions that allow client programs to pass queries and SQL commands to the SQLite Cloud backend server and to receive the results of these queries. In addition to the standard SQLite statements, several other [commands](https://docs.sqlitecloud.io/docs/commands) are supported.
117

12-
## Documentation
13-
If you want to see the Documentation: `make doc` - Warning: A browser window will open and display the documentation to you. The Documentation is updated live while coding. To stop the live mode, press CRTL-C on the command line.
8+
# Getting Started
149

15-
## Development helpers
16-
- Check files with gosec: `make checksec`
17-
- Open the repo in github: `make github`.
18-
- See changes: `make diff`
19-
- Clean dependencies and precompiled code: `make clean`
10+
## Use the SQLite Cloud Client SDK in your Go code
11+
12+
1. Import the package in your Go source code
13+
14+
```
15+
import sqlitecloud "github.com/sqlitecloud/go-sdk"
16+
```
17+
18+
2. download the package, run the [`go mod tidy` command](https://go.dev/ref/mod#go-mod-tidy) to synchronize your module's dependencies:
19+
20+
```
21+
$ go mod tidy
22+
go: downloading github.com/sqlitecloud/go-sdk v1.0.0
23+
```
24+
25+
3. Connect to SQLite Cloud database with a valid [connection string](#get-a-connection-string)
26+
27+
```
28+
db, err := sqlitecloud.Connect("sqlitecloud://user:pass@host.sqlite.cloud:port/dbname")
29+
```
30+
31+
4. Execute queries using a [method](#api-documentation) defined on the `SQCloud` struct, for example `Select`:
32+
33+
```
34+
result, _ := db.Select("SELECT * FROM table1;")
35+
```
36+
37+
38+
39+
The following example shows how to print the content of the table `table1`:
40+
41+
```
42+
package main
43+
44+
import (
45+
"fmt"
46+
"strings"
47+
48+
sqlitecloud "github.com/sqlitecloud/go-sdk"
49+
)
50+
51+
const connectionString = "sqlitecloud://admin:password@host.sqlite.cloud:8860/dbname.sqlite"
52+
53+
func main() {
54+
db, err := sqlitecloud.Connect(connectionString)
55+
if err != nil {
56+
fmt.Println("Connect error: ", err)
57+
}
58+
59+
tables, _ := db.ListTables()
60+
fmt.Printf("Tables: \n\t%s\n", strings.Join(tables, "\n\t"))
61+
62+
fmt.Printf("Table1:\n")
63+
result, _ := db.Select("SELECT * FROM t1;")
64+
for r := uint64(0); r < result.GetNumberOfRows(); r++ {
65+
id, _ := result.GetInt64Value(r, 0)
66+
value, _ := result.GetStringValue(r, 1)
67+
fmt.Printf("\t%d: %s\n", id, value)
68+
}
69+
}
70+
```
71+
72+
## Get a connection string
73+
74+
You can connect to any cloud database using a special connection string in the form:
75+
76+
`sqlitecloud://user:pass@host.com:port/dbname?timeout=10&key2=value2&key3=value3`
77+
78+
To get a valid connection string just follow these instructions:
79+
80+
- Get a [SQLite Cloud](https://sqlitecloud.io/) account. See the [documentation](https://docs.sqlitecloud.io/docs/introduction/login) for details.
81+
- Create a [SQLite Cloud project](https://docs.sqlitecloud.io/docs/introduction/projects)
82+
- Create a [SQLite Cloud database](https://docs.sqlitecloud.io/docs/introduction/databases)
83+
- Get the connection string by clicking on the node address in the [Dashboard Nodes](https://docs.sqlitecloud.io/docs/introduction/nodes) section. A valid connection string for twill be copied in your clipboard.
84+
- add the database name to your connection string
85+
86+
## API Documentation
87+
88+
The complete documentation of the sqlitecloud/go-sdk library is available at: https://pkg.go.dev/github.com/sqlitecloud/go-sdk

connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (this *SQCloud) CheckConnectionParameter() error {
222222
case "":
223223
break
224224
case SQLiteCloudCA:
225-
pem = []byte(SqliteCloudCAPEM)
225+
pem = []byte(sqliteCloudCAPEM)
226226
default:
227227
// check if it is a filepath
228228
_, err := os.Stat(trimmed)

pem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package sqlitecloud
1919

20-
const SqliteCloudCAPEM = `-----BEGIN CERTIFICATE-----
20+
const sqliteCloudCAPEM = `-----BEGIN CERTIFICATE-----
2121
MIID6zCCAtOgAwIBAgIUI0lTm5CfVf3mVP8606CkophcyB4wDQYJKoZIhvcNAQEL
2222
BQAwgYQxCzAJBgNVBAYTAklUMQswCQYDVQQIDAJNTjEQMA4GA1UEBwwHVmlhZGFu
2323
YTEbMBkGA1UECgwSU1FMaXRlIENsb3VkLCBJbmMuMRQwEgYDVQQDDAtTUUxpdGVD

result.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ func (this *Result) Dump() {
107107
}
108108

109109
// ToJSON returns a JSON representation of this query result.
110-
// BUG(andreas): The Result.ToJSON method is not implemented yet.
111110
func (this *Result) ToJSON() string {
112111
buf := new(bytes.Buffer)
113112
_, _ = this.DumpToWriter(bufio.NewWriter(buf), OUTFORMAT_JSON, false, "<AUTO>", "NULL", "", 0, false)

row.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type ResultRow struct {
3434
}
3535

3636
// ToJSON returns a JSON representation of this query result row.
37-
// BUG(andreas): The ResultRow.ToJSON method is not implemented yet.
3837
func (this *ResultRow) ToJSON() ([]byte, error) { return json.Marshal(this) }
3938

4039
// IsFirst returns true if this query result row is the first in the result set, false otherwise.
@@ -113,7 +112,6 @@ func (this *ResultRow) GetName(Column uint64) (string, error) { return this.resu
113112

114113
// GetMaxWidth returns the number of runes of the value in the specified column with the maximum length in this query result.
115114
// The Column index is an unsigned int in the range of 0...GetNumberOfColumns() - 1.
116-
// BUG(andreas): Rename GetWidth->GetmaxWidth
117115
func (this *ResultRow) GetMaxWidth(Column uint64) (uint64, error) {
118116
return this.result.GetMaxColumnWidth(Column)
119117
}

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ func (this *SQCloud) SetKey(Key string, Value string) error {
388388

389389
// GetKey gets the Value of the key Key and returns it as a string value.
390390
// If the Key was not found an error is returned.
391-
// BUG(andreas): If key is not set, DB returns NULL -> does not work with current implementation
392391
func (this *SQCloud) GetKey(Key string) (string, error) {
392+
// BUG(andreas): If key is not set, DB returns NULL -> does not work with current implementation
393393
result, err := this.SelectArray("GET KEY ?", []interface{}{Key})
394394
if result != nil {
395395
defer result.Free()

0 commit comments

Comments
 (0)